HADOOP-16044. ABFS: Better exception handling of DNS errors followup 185/head
authorDa Zhou <da.zhou@microsoft.com>
Mon, 14 Jan 2019 19:32:56 +0000 (19:32 +0000)
committerSteve Loughran <stevel@apache.org>
Mon, 14 Jan 2019 19:32:56 +0000 (19:32 +0000)
Contributed by Da Zhou.

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsRestOperation.java
hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAbfsClient.java

index 3761f4d..fa8f742 100644 (file)
@@ -34,8 +34,6 @@ import org.apache.hadoop.fs.azurebfs.contracts.exceptions.InvalidAbfsRestOperati
 import org.apache.hadoop.fs.azurebfs.constants.HttpHeaderConfigurations;
 import org.apache.hadoop.fs.azurebfs.oauth2.AzureADAuthenticator.HttpException;
 
-import static org.apache.hadoop.fs.azurebfs.contracts.services.AzureServiceErrorCode.UNKNOWN;
-
 /**
  * The AbfsRestOperation for Rest AbfsClient.
  */
@@ -169,6 +167,10 @@ public class AbfsRestOperation {
 
       httpOperation.processResponse(buffer, bufferOffset, bufferLength);
     } catch (IOException ex) {
+      if (ex instanceof UnknownHostException) {
+        LOG.warn(String.format("Unknown host name: %s. Retrying to resolve the host name...", httpOperation.getUrl().getHost()));
+      }
+
       if (LOG.isDebugEnabled()) {
         if (httpOperation != null) {
           LOG.debug("HttpRequestFailure: " + httpOperation.toString(), ex);
@@ -177,14 +179,6 @@ public class AbfsRestOperation {
         }
       }
 
-      if (ex instanceof UnknownHostException) {
-        throw new AbfsRestOperationException(
-                UNKNOWN.getStatusCode(),
-                UNKNOWN.getErrorCode(),
-                String.format("Can not reach endpoint: %s, please check the account setting in configuration file", ex.getMessage()),
-                ex);
-      }
-
       if (!client.getRetryPolicy().shouldRetry(retryCount, -1)) {
         throw new InvalidAbfsRestOperationException(ex);
       }
index ddc1dce..bc05e7d 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.hadoop.fs.azurebfs;
 import java.util.UUID;
 
 import org.junit.Assert;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import org.apache.hadoop.fs.FileSystem;
@@ -55,8 +56,11 @@ public final class ITestAbfsClient extends AbstractAbfsIntegrationTest {
     }
   }
 
+  @Ignore("Enable this to verify the log warning message format for HostNotFoundException")
   @Test
-  public void verifyUnknownHost() throws Exception {
+  public void testUnknownHost() throws Exception {
+    // When hitting hostName not found exception, the retry will take about 14 mins until failed.
+    // This test is to verify that the "Unknown host name: %s. Retrying to resolve the host name..." is logged as warning during the retry.
     AbfsConfiguration conf = this.getConfiguration();
     String accountName = this.getAccountName();
     String fakeAccountName = "fake" + UUID.randomUUID() + accountName.substring(accountName.indexOf("."));
@@ -66,7 +70,7 @@ public final class ITestAbfsClient extends AbstractAbfsIntegrationTest {
     conf.set(FS_AZURE_ACCOUNT_KEY + "." + fakeAccountName, this.getAccountKey());
 
     intercept(AbfsRestOperationException.class,
-            "Can not reach endpoint: " + fakeAccountName,
+            "UnknownHostException: " + fakeAccountName,
             () -> FileSystem.get(conf.getRawConfiguration()));
   }
 }