HADOOP-13249. RetryInvocationHandler need wrap InterruptedException in IOException when call Thread.sleep. Contributed by Zhihai Xu.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/0bbb4ddd Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/0bbb4ddd Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/0bbb4ddd Branch: refs/heads/HDFS-7240 Commit: 0bbb4ddd793063c87927035969884a34f60f2076 Parents: 03fc6b1 Author: Jing Zhao <ji...@apache.org> Authored: Fri Jun 10 10:38:13 2016 -0700 Committer: Jing Zhao <ji...@apache.org> Committed: Fri Jun 10 10:38:13 2016 -0700 ---------------------------------------------------------------------- .../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/0bbb4ddd/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/0bbb4ddd/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: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org