From 3616c7b855962014750a3259a64c6e2a147da884 Mon Sep 17 00:00:00 2001 From: Kihwal Lee Date: Wed, 20 Jan 2016 13:18:25 -0600 Subject: [PATCH] HDFS-9634. webhdfs client side exceptions don't provide enough details. Contributed by Eric Payne. --- .../hadoop/hdfs/web/WebHdfsFileSystem.java | 17 ++++++++++++++++- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../hadoop/hdfs/web/TestWebHdfsTimeouts.java | 14 +++++++------- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java index 1fa95c2fe0b..f9c2c6e1275 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java @@ -24,6 +24,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; import java.net.HttpURLConnection; import java.net.InetSocketAddress; import java.net.MalformedURLException; @@ -502,6 +503,7 @@ abstract class AbstractRunner { new ExcludeDatanodesParam(""); private boolean checkRetry; + private String redirectHost; protected AbstractRunner(final HttpOpParam.Op op, boolean redirected) { this.op = op; @@ -553,7 +555,7 @@ public T run() throws IOException { */ protected HttpURLConnection connect(URL url) throws IOException { //redirect hostname and port - String redirectHost = null; + redirectHost = null; // resolve redirects for a DN operation unless already resolved @@ -658,6 +660,19 @@ private T runWithRetry() throws IOException { throw it; } } catch (IOException ioe) { + // Attempt to include the redirected node in the exception. If the + // attempt to recreate the exception fails, just use the original. + String node = redirectHost; + if (node == null) { + node = url.getAuthority(); + } + try { + ioe = ioe.getClass().getConstructor(String.class) + .newInstance(node + ": " + ioe.getMessage()); + } catch (NoSuchMethodException | SecurityException + | InstantiationException | IllegalAccessException + | IllegalArgumentException | InvocationTargetException e) { + } shouldRetry(ioe, retry); } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index f1e6bdc7851..f41537ed41e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -2624,6 +2624,9 @@ Release 2.7.3 - UNRELEASED HDFS-9569. Log the name of the fsimage being loaded for better supportability. (Yongjun Zhang) + HDFS-9634. webhdfs client side exceptions don't provide enough details + (Eric Payne via kihwal) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTimeouts.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTimeouts.java index bd4d693795b..3a87d422a6c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTimeouts.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTimeouts.java @@ -115,7 +115,7 @@ public void testConnectTimeout() throws Exception { fs.listFiles(new Path("/"), false); fail("expected timeout"); } catch (SocketTimeoutException e) { - assertEquals("connect timed out", e.getMessage()); + assertEquals(fs.getUri().getAuthority() + ": connect timed out", e.getMessage()); } } @@ -128,7 +128,7 @@ public void testReadTimeout() throws Exception { fs.listFiles(new Path("/"), false); fail("expected timeout"); } catch (SocketTimeoutException e) { - assertEquals("Read timed out", e.getMessage()); + assertEquals(fs.getUri().getAuthority() + ": Read timed out", e.getMessage()); } } @@ -143,7 +143,7 @@ public void testAuthUrlConnectTimeout() throws Exception { fs.getDelegationToken("renewer"); fail("expected timeout"); } catch (SocketTimeoutException e) { - assertEquals("connect timed out", e.getMessage()); + assertEquals(fs.getUri().getAuthority() + ": connect timed out", e.getMessage()); } } @@ -157,7 +157,7 @@ public void testAuthUrlReadTimeout() throws Exception { fs.getDelegationToken("renewer"); fail("expected timeout"); } catch (SocketTimeoutException e) { - assertEquals("Read timed out", e.getMessage()); + assertEquals(fs.getUri().getAuthority() + ": Read timed out", e.getMessage()); } } @@ -172,7 +172,7 @@ public void testRedirectConnectTimeout() throws Exception { fs.getFileChecksum(new Path("/file")); fail("expected timeout"); } catch (SocketTimeoutException e) { - assertEquals("connect timed out", e.getMessage()); + assertEquals(fs.getUri().getAuthority() + ": connect timed out", e.getMessage()); } } @@ -187,7 +187,7 @@ public void testRedirectReadTimeout() throws Exception { fs.getFileChecksum(new Path("/file")); fail("expected timeout"); } catch (SocketTimeoutException e) { - assertEquals("Read timed out", e.getMessage()); + assertEquals(fs.getUri().getAuthority() + ": Read timed out", e.getMessage()); } } @@ -203,7 +203,7 @@ public void testTwoStepWriteConnectTimeout() throws Exception { os = fs.create(new Path("/file")); fail("expected timeout"); } catch (SocketTimeoutException e) { - assertEquals("connect timed out", e.getMessage()); + assertEquals(fs.getUri().getAuthority() + ": connect timed out", e.getMessage()); } finally { IOUtils.cleanup(LOG, os); }