浏览代码

HADOOP-16683. Disable retry of FailoverOnNetworkExceptionRetry in case of wrapped AccessControlException. Contributed by Adam Antal

Szilard Nemeth 5 年之前
父节点
当前提交
3d249301f4

+ 11 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicies.java

@@ -689,7 +689,8 @@ public class RetryPolicies {
       } else if (e instanceof InvalidToken) {
       } else if (e instanceof InvalidToken) {
         return new RetryAction(RetryAction.RetryDecision.FAIL, 0,
         return new RetryAction(RetryAction.RetryDecision.FAIL, 0,
             "Invalid or Cancelled Token");
             "Invalid or Cancelled Token");
-      } else if (e instanceof AccessControlException) {
+      } else if (e instanceof AccessControlException ||
+              hasWrappedAccessControlException(e)) {
         return new RetryAction(RetryAction.RetryDecision.FAIL, 0,
         return new RetryAction(RetryAction.RetryDecision.FAIL, 0,
             "Access denied");
             "Access denied");
       } else if (e instanceof SocketException
       } else if (e instanceof SocketException
@@ -759,4 +760,13 @@ public class RetryPolicies {
     return unwrapped instanceof RetriableException ? 
     return unwrapped instanceof RetriableException ? 
         (RetriableException) unwrapped : null;
         (RetriableException) unwrapped : null;
   }
   }
+
+  private static boolean hasWrappedAccessControlException(Exception e) {
+    Throwable throwable = e;
+    while (!(throwable instanceof AccessControlException) &&
+        throwable.getCause() != null) {
+      throwable = throwable.getCause();
+    }
+    return throwable instanceof AccessControlException;
+  }
 }
 }

+ 19 - 0
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestRetryProxy.java

@@ -377,4 +377,23 @@ public class TestRetryProxy {
       assertEquals(RetryDecision.FAIL, caughtRetryAction.action);
       assertEquals(RetryDecision.FAIL, caughtRetryAction.action);
     }
     }
   }
   }
+
+  @Test
+  public void testWrappedAccessControlException() throws Exception {
+    RetryPolicy policy = mock(RetryPolicy.class);
+    RetryPolicy realPolicy = RetryPolicies.failoverOnNetworkException(5);
+    setupMockPolicy(policy, realPolicy);
+
+    UnreliableInterface unreliable = (UnreliableInterface) RetryProxy.create(
+        UnreliableInterface.class, unreliableImpl, policy);
+
+    try {
+      unreliable.failsWithWrappedAccessControlException();
+      fail("Should fail");
+    } catch (IOException expected) {
+      verify(policy, times(1)).shouldRetry(any(Exception.class), anyInt(),
+          anyInt(), anyBoolean());
+      assertEquals(RetryDecision.FAIL, caughtRetryAction.action);
+    }
+  }
 }
 }

+ 7 - 0
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/UnreliableImplementation.java

@@ -139,6 +139,13 @@ class UnreliableImplementation implements UnreliableInterface {
     }
     }
   }
   }
 
 
+  public void failsWithWrappedAccessControlException()
+      throws IOException {
+    AccessControlException ace = new AccessControlException();
+    IOException ioe = new IOException(ace);
+    throw new IOException(ioe);
+  }
+
   @Override
   @Override
   public String succeedsOnceThenFailsReturningString()
   public String succeedsOnceThenFailsReturningString()
       throws UnreliableException, IOException, StandbyException {
       throws UnreliableException, IOException, StandbyException {

+ 4 - 0
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/UnreliableInterface.java

@@ -83,6 +83,10 @@ public interface UnreliableInterface {
   void failsWithAccessControlExceptionEightTimes()
   void failsWithAccessControlExceptionEightTimes()
       throws AccessControlException;
       throws AccessControlException;
 
 
+  @Idempotent
+  void failsWithWrappedAccessControlException()
+      throws IOException;
+
   public String succeedsOnceThenFailsReturningString()
   public String succeedsOnceThenFailsReturningString()
       throws UnreliableException, StandbyException, IOException;
       throws UnreliableException, StandbyException, IOException;
   @Idempotent
   @Idempotent