deniskuzZ commented on code in PR #6955:
URL: https://github.com/apache/hive/pull/6955#discussion_r4641859322


##########
common/src/java/org/apache/hadoop/hive/common/JavaUtils.java:
##########
@@ -130,4 +133,26 @@ public static Throwable findRootCause(Throwable throwable) 
{
     }
     return rootCause;
   }
+
+  /**
+   * Whether a failure is the current thread being interrupted rather than the 
operation failing on
+   * its own: the thread's interrupt flag is set, or the cause chain holds an
+   * {@link InterruptedException}, a {@link ClosedByInterruptException} or an
+   * {@link InterruptedIOException}. The whole chain is walked, not just the 
root cause, because
+   * Hadoop's IPC and filesystem clients wrap an interrupt in an {@code 
InterruptedIOException} of
+   * their own. A {@link SocketTimeoutException} is an {@code 
InterruptedIOException} too, but it is
+   * a timeout, not an interrupt.
+   */
+  public static boolean isInterrupt(Throwable throwable) {
+    if (Thread.currentThread().isInterrupted()) {
+      return true;
+    }
+    for (Throwable t = throwable; t != null; t = t.getCause()) {

Review Comment:
   Nit: commons-lang3's ExceptionUtils.stream already walks the cause chain, 
and unlike this loop it stops on a cause cycle:         
   ````                                                                         
  
    /**                                                                         
                                                                                
                                                 
        * Whether a failure is the current thread being interrupted rather than 
the operation failing on its own.                                               
                                                    
        * The whole cause chain is checked, not just the root cause, because 
Hadoop's IPC and filesystem clients                                             
                                                       
        * wrap an interrupt in an InterruptedIOException of their own.          
                                                                                
                                                    
        */                                                                      
                                                                                
                                                    
       public static boolean isInterrupt(Throwable throwable) {                 
                                                                                
                                                    
         return Thread.currentThread().isInterrupted()                          
                                                                                
                                                    
             || 
ExceptionUtils.stream(throwable).anyMatch(JavaUtils::isInterruptType);          
                                                                                
                                    
       }                                                                        
                                                                                
                                                    
                                                                                
                                                                                
                                                    
       // A SocketTimeoutException is an InterruptedIOException too, but it is 
a timeout, not an interrupt.                                                    
                                                     
       private static boolean isInterruptType(Throwable t) {                    
                                                                                
                                                    
         return t instanceof InterruptedException                               
                                                                                
                                                    
             || t instanceof ClosedByInterruptException                         
                                                                                
                                                    
             || (t instanceof InterruptedIOException && !(t instanceof 
SocketTimeoutException));                                                       
                                                             
       }           
   ````                                                                         
                                    
   
   The javadoc could drop the list of exception types, since the code shows 
them. The two sentences on why it walks the whole chain and why it excludes 
SocketTimeoutException are worth keeping. 



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to