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

This commit is contained in:
Szilard Nemeth 2019-11-09 15:43:53 +01:00
parent ceb9c6175e
commit 3d249301f4
4 changed files with 41 additions and 1 deletions

View File

@ -689,7 +689,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
@ -759,4 +760,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;
}
}

View File

@ -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);
}
}
}

View File

@ -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 {

View File

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