Repository: hadoop Updated Branches: refs/heads/branch-2.8 5af2af15e -> ce788c207
HADOOP-13249. RetryInvocationHandler need wrap InterruptedException in IOException when call Thread.sleep. Contributed by Zhihai Xu. (cherry picked from commit 0bbb4ddd793063c87927035969884a34f60f2076) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/e251654e Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/e251654e Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/e251654e Branch: refs/heads/branch-2.8 Commit: e251654ee4082d86dc4cca9e58d8a867af47e9ec Parents: 5af2af1 Author: Jing Zhao <[email protected]> Authored: Fri Jun 10 10:38:13 2016 -0700 Committer: Tsz-Wo Nicholas Sze <[email protected]> Committed: Sat Jun 25 15:51:35 2016 +0800 ---------------------------------------------------------------------- .../apache/hadoop/io/retry/RetryInvocationHandler.java | 12 +++++++++++- .../java/org/apache/hadoop/io/retry/TestRetryProxy.java | 7 +++++-- 2 files changed, 16 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/e251654e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java index f2b2c99..5198c0d 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java @@ -27,6 +27,7 @@ import org.apache.hadoop.ipc.*; import org.apache.hadoop.ipc.Client.ConnectionId; import java.io.IOException; +import java.io.InterruptedIOException; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -297,7 +298,16 @@ public class RetryInvocationHandler<T> implements RpcInvocationHandler { log(method, isFailover, counters.failovers, retryInfo.delay, ex); if (retryInfo.delay > 0) { - Thread.sleep(retryInfo.delay); + try { + Thread.sleep(retryInfo.delay); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + LOG.warn("Interrupted while waiting to retry", e); + InterruptedIOException intIOE = new InterruptedIOException( + "Retry interrupted"); + intIOE.initCause(e); + throw intIOE; + } } if (isFailover) { http://git-wip-us.apache.org/repos/asf/hadoop/blob/e251654e/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestRetryProxy.java ---------------------------------------------------------------------- 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 41c1be4..649af89 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 @@ -31,6 +31,7 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import java.io.IOException; +import java.io.InterruptedIOException; import java.lang.reflect.UndeclaredThrowableException; import java.util.Collections; import java.util.Map; @@ -320,7 +321,9 @@ public class TestRetryProxy { futureThread.get().interrupt(); Throwable e = future.get(1, TimeUnit.SECONDS); // should return immediately assertNotNull(e); - assertEquals(InterruptedException.class, e.getClass()); - assertEquals("sleep interrupted", e.getMessage()); + assertEquals(InterruptedIOException.class, e.getClass()); + assertEquals("Retry interrupted", e.getMessage()); + assertEquals(InterruptedException.class, e.getCause().getClass()); + assertEquals("sleep interrupted", e.getCause().getMessage()); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
