HADOOP-16683. Disable retry of FailoverOnNetworkExceptionRetry in case of wrapped AccessControlException. Contributed by Adam Antal
This commit is contained in:
parent
ceb9c6175e
commit
3d249301f4
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -83,6 +83,10 @@ public interface UnreliableInterface {
|
|||
void failsWithAccessControlExceptionEightTimes()
|
||||
throws AccessControlException;
|
||||
|
||||
@Idempotent
|
||||
void failsWithWrappedAccessControlException()
|
||||
throws IOException;
|
||||
|
||||
public String succeedsOnceThenFailsReturningString()
|
||||
throws UnreliableException, StandbyException, IOException;
|
||||
@Idempotent
|
||||
|
|
Loading…
Reference in New Issue