Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 72A85200BD2 for ; Sat, 3 Dec 2016 12:18:34 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 71B13160B2A; Sat, 3 Dec 2016 11:18:34 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id BC14C160B0E for ; Sat, 3 Dec 2016 12:18:33 +0100 (CET) Received: (qmail 56600 invoked by uid 500); 3 Dec 2016 11:18:32 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 56543 invoked by uid 99); 3 Dec 2016 11:18:32 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 03 Dec 2016 11:18:32 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6CE69E02E4; Sat, 3 Dec 2016 11:18:32 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: asuresh@apache.org To: common-commits@hadoop.apache.org Date: Sat, 03 Dec 2016 11:18:35 -0000 Message-Id: <860c1b7a63234ffc92958800e578b25d@git.apache.org> In-Reply-To: <5268977ae71d4a239856992dd3aa7e60@git.apache.org> References: <5268977ae71d4a239856992dd3aa7e60@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [4/8] hadoop git commit: HADOOP-13857. S3AUtils.translateException to map (wrapped) InterruptedExceptions to InterruptedIOEs. Contributed by Steve Loughran archived-at: Sat, 03 Dec 2016 11:18:34 -0000 HADOOP-13857. S3AUtils.translateException to map (wrapped) InterruptedExceptions to InterruptedIOEs. Contributed by Steve Loughran Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/2ff84a00 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/2ff84a00 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/2ff84a00 Branch: refs/heads/YARN-5085 Commit: 2ff84a00405e977b1fd791cfb974244580dd5ae8 Parents: c7ff34f Author: Mingliang Liu Authored: Fri Dec 2 13:36:04 2016 -0800 Committer: Mingliang Liu Committed: Fri Dec 2 13:36:04 2016 -0800 ---------------------------------------------------------------------- .../java/org/apache/hadoop/fs/s3a/S3AUtils.java | 23 ++++++++++++ .../fs/s3a/TestS3AExceptionTranslation.java | 38 ++++++++++++++++++++ 2 files changed, 61 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/2ff84a00/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AUtils.java ---------------------------------------------------------------------- diff --git a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AUtils.java b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AUtils.java index 49f8862..dedbfd4 100644 --- a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AUtils.java +++ b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AUtils.java @@ -40,6 +40,7 @@ import org.slf4j.Logger; import java.io.EOFException; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InterruptedIOException; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -113,6 +114,10 @@ public final class S3AUtils { path != null ? (" on " + path) : "", exception); if (!(exception instanceof AmazonServiceException)) { + if (containsInterruptedException(exception)) { + return (IOException)new InterruptedIOException(message) + .initCause(exception); + } return new AWSClientIOException(message, exception); } else { @@ -195,6 +200,24 @@ public final class S3AUtils { } /** + * Recurse down the exception loop looking for any inner details about + * an interrupted exception. + * @param thrown exception thrown + * @return true if down the execution chain the operation was an interrupt + */ + static boolean containsInterruptedException(Throwable thrown) { + if (thrown == null) { + return false; + } + if (thrown instanceof InterruptedException || + thrown instanceof InterruptedIOException) { + return true; + } + // tail recurse + return containsInterruptedException(thrown.getCause()); + } + + /** * Get low level details of an amazon exception for logging; multi-line. * @param e exception * @return string details http://git-wip-us.apache.org/repos/asf/hadoop/blob/2ff84a00/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestS3AExceptionTranslation.java ---------------------------------------------------------------------- diff --git a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestS3AExceptionTranslation.java b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestS3AExceptionTranslation.java index a7dafa0..e548ac2 100644 --- a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestS3AExceptionTranslation.java +++ b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestS3AExceptionTranslation.java @@ -25,9 +25,12 @@ import static org.junit.Assert.*; import java.io.EOFException; import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InterruptedIOException; import java.nio.file.AccessDeniedException; import java.util.Collections; import java.util.Map; +import java.util.concurrent.ExecutionException; import com.amazonaws.AmazonClientException; import com.amazonaws.AmazonServiceException; @@ -124,4 +127,39 @@ public class TestS3AExceptionTranslation { return verifyExceptionClass(clazz, translateException("test", "/", exception)); } + + private void assertContainsInterrupted(boolean expected, Throwable thrown) + throws Throwable { + if (containsInterruptedException(thrown) != expected) { + throw thrown; + } + } + + @Test + public void testInterruptExceptionDetecting() throws Throwable { + InterruptedException interrupted = new InterruptedException("irq"); + assertContainsInterrupted(true, interrupted); + IOException ioe = new IOException("ioe"); + assertContainsInterrupted(false, ioe); + assertContainsInterrupted(true, ioe.initCause(interrupted)); + assertContainsInterrupted(true, + new InterruptedIOException("ioirq")); + } + + @Test(expected = InterruptedIOException.class) + public void testExtractInterrupted() throws Throwable { + throw extractException("", "", + new ExecutionException( + new AmazonClientException( + new InterruptedException("")))); + } + + @Test(expected = InterruptedIOException.class) + public void testExtractInterruptedIO() throws Throwable { + throw extractException("", "", + new ExecutionException( + new AmazonClientException( + new InterruptedIOException("")))); + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org