diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicies.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicies.java index 842811edb39..757445f957a 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicies.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicies.java @@ -181,6 +181,13 @@ public class RetryPolicies { maxRetries, delayMillis, maxDelayBase); } + public static final RetryPolicy failoverOnNetworkException( + RetryPolicy fallbackPolicy, int maxFailovers, int maxRetries, + long delayMillis, long maxDelayBase, int nnSize) { + return new FailoverOnNetworkExceptionRetry(fallbackPolicy, maxFailovers, + maxRetries, delayMillis, maxDelayBase, nnSize); + } + static class TryOnceThenFail implements RetryPolicy { @Override public RetryAction shouldRetry(Exception e, int retries, int failovers, @@ -620,12 +627,13 @@ public class RetryPolicies { * Fall back on underlying retry policy otherwise. */ static class FailoverOnNetworkExceptionRetry implements RetryPolicy { - + private static final int minNnSize = 2; private RetryPolicy fallbackPolicy; private int maxFailovers; private int maxRetries; private long delayMillis; private long maxDelayBase; + private int nnSize; public FailoverOnNetworkExceptionRetry(RetryPolicy fallbackPolicy, int maxFailovers) { @@ -639,11 +647,18 @@ public class RetryPolicies { public FailoverOnNetworkExceptionRetry(RetryPolicy fallbackPolicy, int maxFailovers, int maxRetries, long delayMillis, long maxDelayBase) { + this(fallbackPolicy, maxFailovers, maxRetries, delayMillis, maxDelayBase, minNnSize); + } + + public FailoverOnNetworkExceptionRetry(RetryPolicy fallbackPolicy, + int maxFailovers, int maxRetries, long delayMillis, long maxDelayBase, int nnSize) { this.fallbackPolicy = fallbackPolicy; this.maxFailovers = maxFailovers; this.maxRetries = maxRetries; this.delayMillis = delayMillis; this.maxDelayBase = maxDelayBase; + // set the nn size to reduce the failover sleep time. + this.nnSize = nnSize; } /** @@ -651,7 +666,7 @@ public class RetryPolicies { * sleep exponentially otherwise */ private long getFailoverOrRetrySleepTime(int times) { - return times == 0 ? 0 : + return times < (nnSize - 1) ? 0 : calculateExponentialTime(delayMillis, times, maxDelayBase); } diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/NameNodeProxiesClient.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/NameNodeProxiesClient.java index aa9577330cf..a99673355b5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/NameNodeProxiesClient.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/NameNodeProxiesClient.java @@ -316,13 +316,16 @@ public class NameNodeProxiesClient { Configuration conf, URI nameNodeUri, Class xface, AbstractNNFailoverProxyProvider failoverProxyProvider) { Preconditions.checkNotNull(failoverProxyProvider); + Map> map = + DFSUtilClient.getAddresses(conf, null, HdfsClientConfigKeys.DFS_NAMENODE_RPC_ADDRESS_KEY); + Map nnMap = map.get(nameNodeUri.getHost()); // HA case DfsClientConf config = new DfsClientConf(conf); T proxy = (T) RetryProxy.create(xface, failoverProxyProvider, RetryPolicies.failoverOnNetworkException( RetryPolicies.TRY_ONCE_THEN_FAIL, config.getMaxFailoverAttempts(), config.getMaxRetryAttempts(), config.getFailoverSleepBaseMillis(), - config.getFailoverSleepMaxMillis())); + config.getFailoverSleepMaxMillis(), nnMap.size())); Text dtService; if (failoverProxyProvider.useLogicalURI()) {