zhaoyim commented on a change in pull request #746: HBASE-23195 
FSDataInputStreamWrapper unbuffer can NOT invoke the clas…
URL: https://github.com/apache/hbase/pull/746#discussion_r346644880
 
 

 ##########
 File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/io/FSDataInputStreamWrapper.java
 ##########
 @@ -270,39 +269,23 @@ public void unbuffer() {
       if (this.instanceOfCanUnbuffer == null) {
         // To ensure we compute whether the stream is instance of CanUnbuffer 
only once.
         this.instanceOfCanUnbuffer = false;
-        Class<?>[] streamInterfaces = streamClass.getInterfaces();
-        for (Class c : streamInterfaces) {
-          if 
(c.getCanonicalName().toString().equals("org.apache.hadoop.fs.CanUnbuffer")) {
-            try {
-              this.unbuffer = streamClass.getDeclaredMethod("unbuffer");
-            } catch (NoSuchMethodException | SecurityException e) {
-              if (isLogTraceEnabled) {
-                LOG.trace("Failed to find 'unbuffer' method in class " + 
streamClass
-                    + " . So there may be a TCP socket connection "
-                    + "left open in CLOSE_WAIT state.", e);
-              }
-              return;
-            }
-            this.instanceOfCanUnbuffer = true;
-            break;
-          }
+        if (CanUnbuffer.class.isAssignableFrom(streamClass)) {
+          this.unbuffer = (CanUnbuffer) wrappedStream;
+          this.instanceOfCanUnbuffer = true;
         }
       }
       if (this.instanceOfCanUnbuffer) {
         try {
-          this.unbuffer.invoke(wrappedStream);
-        } catch (IllegalAccessException | IllegalArgumentException | 
InvocationTargetException e) {
+          this.unbuffer.unbuffer();
+        } catch (UnsupportedOperationException e){
 
 Review comment:
   For the Hadoop-common 2.X project org.apache.hadoop.fs.FSDataInputStream has 
   `
   public void unbuffer()
   {
         try {
                ((CanUnbuffer) this.in).unbuffer();
                         } catch (ClassCastException e) {
                        throw new UnsupportedOperationException(
                                        "this stream " + 
this.in.getClass().getName() + " does not " + "support unbuffering.");
                        }
   }
   `
   
   For the hadoop trunk branch org.apache.hadoop.fs.StreamCapabilitiesPolicy 
throw
   `
       } catch (ClassCastException e) {
         throw new UnsupportedOperationException(in.getClass().getName() + ": "
                 + CAN_UNBUFFER_NOT_IMPLEMENTED_MESSAGE);
       }
   `
   
   If I am wrong, please fell free correct me. Thanks!

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to