protected internal static RetryPolicy CreateRetryPolicy(Configuration conf, string maxWaitTimeStr, long defMaxWaitTime, string connectRetryIntervalStr, long defRetryInterval ) { long maxWaitTime = conf.GetLong(maxWaitTimeStr, defMaxWaitTime); long retryIntervalMS = conf.GetLong(connectRetryIntervalStr, defRetryInterval); if (maxWaitTime == -1) { // wait forever. return(RetryPolicies.RetryForever); } Preconditions.CheckArgument(maxWaitTime > 0, "Invalid Configuration. " + maxWaitTimeStr + " should be a positive value."); Preconditions.CheckArgument(retryIntervalMS > 0, "Invalid Configuration. " + connectRetryIntervalStr + "should be a positive value."); RetryPolicy retryPolicy = RetryPolicies.RetryUpToMaximumTimeWithFixedSleep(maxWaitTime , retryIntervalMS, TimeUnit.Milliseconds); IDictionary <Type, RetryPolicy> exceptionToPolicyMap = new Dictionary <Type, RetryPolicy >(); exceptionToPolicyMap[typeof(EOFException)] = retryPolicy; exceptionToPolicyMap[typeof(ConnectException)] = retryPolicy; exceptionToPolicyMap[typeof(NoRouteToHostException)] = retryPolicy; exceptionToPolicyMap[typeof(UnknownHostException)] = retryPolicy; exceptionToPolicyMap[typeof(RetriableException)] = retryPolicy; exceptionToPolicyMap[typeof(SocketException)] = retryPolicy; exceptionToPolicyMap[typeof(NMNotYetReadyException)] = retryPolicy; return(RetryPolicies.RetryByException(RetryPolicies.TryOnceThenFail, exceptionToPolicyMap )); }
public static RetryPolicy CreateRetryPolicy(Configuration conf) { long rmConnectWaitMS = conf.GetLong(YarnConfiguration.ResourcemanagerConnectMaxWaitMs , YarnConfiguration.DefaultResourcemanagerConnectMaxWaitMs); long rmConnectionRetryIntervalMS = conf.GetLong(YarnConfiguration.ResourcemanagerConnectRetryIntervalMs , YarnConfiguration.DefaultResourcemanagerConnectRetryIntervalMs); bool waitForEver = (rmConnectWaitMS == -1); if (!waitForEver) { if (rmConnectWaitMS < 0) { throw new YarnRuntimeException("Invalid Configuration. " + YarnConfiguration.ResourcemanagerConnectMaxWaitMs + " can be -1, but can not be other negative numbers"); } // try connect once if (rmConnectWaitMS < rmConnectionRetryIntervalMS) { Log.Warn(YarnConfiguration.ResourcemanagerConnectMaxWaitMs + " is smaller than " + YarnConfiguration.ResourcemanagerConnectRetryIntervalMs + ". Only try connect once." ); rmConnectWaitMS = 0; } } // Handle HA case first if (HAUtil.IsHAEnabled(conf)) { long failoverSleepBaseMs = conf.GetLong(YarnConfiguration.ClientFailoverSleeptimeBaseMs , rmConnectionRetryIntervalMS); long failoverSleepMaxMs = conf.GetLong(YarnConfiguration.ClientFailoverSleeptimeMaxMs , rmConnectionRetryIntervalMS); int maxFailoverAttempts = conf.GetInt(YarnConfiguration.ClientFailoverMaxAttempts , -1); if (maxFailoverAttempts == -1) { if (waitForEver) { maxFailoverAttempts = int.MaxValue; } else { maxFailoverAttempts = (int)(rmConnectWaitMS / failoverSleepBaseMs); } } return(RetryPolicies.FailoverOnNetworkException(RetryPolicies.TryOnceThenFail, maxFailoverAttempts , failoverSleepBaseMs, failoverSleepMaxMs)); } if (rmConnectionRetryIntervalMS < 0) { throw new YarnRuntimeException("Invalid Configuration. " + YarnConfiguration.ResourcemanagerConnectRetryIntervalMs + " should not be negative."); } RetryPolicy retryPolicy = null; if (waitForEver) { retryPolicy = RetryPolicies.RetryForever; } else { retryPolicy = RetryPolicies.RetryUpToMaximumTimeWithFixedSleep(rmConnectWaitMS, rmConnectionRetryIntervalMS , TimeUnit.Milliseconds); } IDictionary <Type, RetryPolicy> exceptionToPolicyMap = new Dictionary <Type, RetryPolicy >(); exceptionToPolicyMap[typeof(EOFException)] = retryPolicy; exceptionToPolicyMap[typeof(ConnectException)] = retryPolicy; exceptionToPolicyMap[typeof(NoRouteToHostException)] = retryPolicy; exceptionToPolicyMap[typeof(UnknownHostException)] = retryPolicy; exceptionToPolicyMap[typeof(ConnectTimeoutException)] = retryPolicy; exceptionToPolicyMap[typeof(RetriableException)] = retryPolicy; exceptionToPolicyMap[typeof(SocketException)] = retryPolicy; return(RetryPolicies.RetryByException(RetryPolicies.TryOnceThenFail, exceptionToPolicyMap )); }