This is an automated email from the ASF dual-hosted git repository.

kihwal pushed a commit to branch branch-2.10
in repository https://gitbox.apache.org/repos/asf/hadoop.git

commit 8d4671b611eb9f5a1a2f597f92fa6492a320997e
Author: Kihwal Lee <kih...@apache.org>
AuthorDate: Fri Jan 24 11:08:24 2020 -0600

    HADOOP-16683. Disable retry of FailoverOnNetworkExceptionRetry in case of 
wrapped AccessControlException. Contributed by Adam Antal
    
    (cherry picked from commit 3d249301f42130de80ab3ecf8c783bb51b0fa8a3)
---
 .../org/apache/hadoop/io/retry/RetryPolicies.java     | 12 +++++++++++-
 .../org/apache/hadoop/io/retry/TestRetryProxy.java    | 19 +++++++++++++++++++
 .../hadoop/io/retry/UnreliableImplementation.java     |  7 +++++++
 .../apache/hadoop/io/retry/UnreliableInterface.java   |  4 ++++
 4 files changed, 41 insertions(+), 1 deletion(-)

diff --git 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicies.java
 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicies.java
index a89c3a7..fcbcc86 100644
--- 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicies.java
+++ 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicies.java
@@ -690,7 +690,8 @@ public class RetryPolicies {
       } else if (e instanceof InvalidToken) {
         return new RetryAction(RetryAction.RetryDecision.FAIL, 0,
             "Invalid or Cancelled Token");
-      } else if (e instanceof AccessControlException) {
+      } else if (e instanceof AccessControlException ||
+              hasWrappedAccessControlException(e)) {
         return new RetryAction(RetryAction.RetryDecision.FAIL, 0,
             "Access denied");
       } else if (e instanceof SocketException
@@ -761,4 +762,13 @@ public class RetryPolicies {
     return unwrapped instanceof RetriableException ? 
         (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;
+  }
 }
diff --git 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestRetryProxy.java
 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestRetryProxy.java
index 2116fb2..a1135a0 100644
--- 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestRetryProxy.java
+++ 
b/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);
     }
   }
+
+  @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);
+    }
+  }
 }
diff --git 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/UnreliableImplementation.java
 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/UnreliableImplementation.java
index 97031fd..3734474 100644
--- 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/UnreliableImplementation.java
+++ 
b/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
   public String succeedsOnceThenFailsReturningString()
       throws UnreliableException, IOException, StandbyException {
diff --git 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/UnreliableInterface.java
 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/UnreliableInterface.java
index 738a760..80bf47d 100644
--- 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/UnreliableInterface.java
+++ 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/UnreliableInterface.java
@@ -83,6 +83,10 @@ public interface UnreliableInterface {
   void failsWithAccessControlExceptionEightTimes()
       throws AccessControlException;
 
+  @Idempotent
+  void failsWithWrappedAccessControlException()
+      throws IOException;
+
   public String succeedsOnceThenFailsReturningString()
       throws UnreliableException, StandbyException, IOException;
   @Idempotent


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to