use of org.apache.hadoop.io.retry.RetryPolicy in project hadoop by apache.
the class TestReuseRpcConnections method testRetryPolicyTryOnceThenFail.
@Test(timeout = 60000)
public void testRetryPolicyTryOnceThenFail() throws Exception {
final RetryPolicy rp1 = TestConnectionRetryPolicy.newTryOnceThenFail();
final RetryPolicy rp2 = TestConnectionRetryPolicy.newTryOnceThenFail();
verifyRetryPolicyReuseConnections(rp1, rp2, RetryPolicies.RETRY_FOREVER);
}
use of org.apache.hadoop.io.retry.RetryPolicy in project hadoop by apache.
the class TestUserGroupInformation method testGetNextRetryTime.
@Test
public void testGetNextRetryTime() throws Exception {
GenericTestUtils.setLogLevel(UserGroupInformation.LOG, Level.DEBUG);
final long reloginInterval = 1;
final long reloginIntervalMs = reloginInterval * 1000;
// Relogin happens every 1 second.
conf.setLong(HADOOP_KERBEROS_MIN_SECONDS_BEFORE_RELOGIN, reloginInterval);
SecurityUtil.setAuthenticationMethod(AuthenticationMethod.KERBEROS, conf);
UserGroupInformation.setConfiguration(conf);
// Suppose tgt start time is now, end time is 20 seconds from now.
final long now = Time.now();
final Date endDate = new Date(now + 20000);
// Explicitly test the exponential back-off logic.
// Suppose some time (10 seconds) passed.
// Verify exponential backoff and max=(login interval before endTime).
final long currentTime = now + 10000;
final long endTime = endDate.getTime();
assertEquals(0, UserGroupInformation.metrics.getRenewalFailures().value());
RetryPolicy rp = RetryPolicies.exponentialBackoffRetry(Long.SIZE - 2, 1000, TimeUnit.MILLISECONDS);
long lastRetry = UserGroupInformation.getNextTgtRenewalTime(endTime, currentTime, rp);
assertWithinBounds(UserGroupInformation.metrics.getRenewalFailures().value(), lastRetry, reloginIntervalMs, currentTime);
UserGroupInformation.metrics.getRenewalFailures().incr();
lastRetry = UserGroupInformation.getNextTgtRenewalTime(endTime, currentTime, rp);
assertWithinBounds(UserGroupInformation.metrics.getRenewalFailures().value(), lastRetry, reloginIntervalMs, currentTime);
UserGroupInformation.metrics.getRenewalFailures().incr();
lastRetry = UserGroupInformation.getNextTgtRenewalTime(endTime, currentTime, rp);
assertWithinBounds(UserGroupInformation.metrics.getRenewalFailures().value(), lastRetry, reloginIntervalMs, currentTime);
UserGroupInformation.metrics.getRenewalFailures().incr();
lastRetry = UserGroupInformation.getNextTgtRenewalTime(endTime, currentTime, rp);
assertWithinBounds(UserGroupInformation.metrics.getRenewalFailures().value(), lastRetry, reloginIntervalMs, currentTime);
// last try should be right before expiry.
UserGroupInformation.metrics.getRenewalFailures().incr();
lastRetry = UserGroupInformation.getNextTgtRenewalTime(endTime, currentTime, rp);
String str = "5th retry, now:" + currentTime + ", retry:" + lastRetry;
LOG.info(str);
assertEquals(str, endTime - reloginIntervalMs, lastRetry);
// make sure no more retries after (tgt endTime - login interval).
UserGroupInformation.metrics.getRenewalFailures().incr();
lastRetry = UserGroupInformation.getNextTgtRenewalTime(endTime, currentTime, rp);
str = "overflow retry, now:" + currentTime + ", retry:" + lastRetry;
LOG.info(str);
assertEquals(str, endTime - reloginIntervalMs, lastRetry);
}
use of org.apache.hadoop.io.retry.RetryPolicy in project hadoop by apache.
the class NameNodeProxies method createNNProxyWithNamenodeProtocol.
private static NamenodeProtocol createNNProxyWithNamenodeProtocol(InetSocketAddress address, Configuration conf, UserGroupInformation ugi, boolean withRetries) throws IOException {
NamenodeProtocolPB proxy = (NamenodeProtocolPB) createNameNodeProxy(address, conf, ugi, NamenodeProtocolPB.class, 0);
if (withRetries) {
// create the proxy with retries
RetryPolicy timeoutPolicy = RetryPolicies.exponentialBackoffRetry(5, 200, TimeUnit.MILLISECONDS);
Map<String, RetryPolicy> methodNameToPolicyMap = new HashMap<String, RetryPolicy>();
methodNameToPolicyMap.put("getBlocks", timeoutPolicy);
methodNameToPolicyMap.put("getAccessKeys", timeoutPolicy);
NamenodeProtocol translatorProxy = new NamenodeProtocolTranslatorPB(proxy);
return (NamenodeProtocol) RetryProxy.create(NamenodeProtocol.class, translatorProxy, methodNameToPolicyMap);
} else {
return new NamenodeProtocolTranslatorPB(proxy);
}
}
use of org.apache.hadoop.io.retry.RetryPolicy in project hadoop by apache.
the class RMProxy method createRMProxy.
/**
* Currently, used by Client and AM only
* Create a proxy for the specified protocol. For non-HA,
* this is a direct connection to the ResourceManager address. When HA is
* enabled, the proxy handles the failover between the ResourceManagers as
* well.
*/
@Private
protected static <T> T createRMProxy(final Configuration configuration, final Class<T> protocol, RMProxy instance) throws IOException {
YarnConfiguration conf = (configuration instanceof YarnConfiguration) ? (YarnConfiguration) configuration : new YarnConfiguration(configuration);
RetryPolicy retryPolicy = createRetryPolicy(conf, HAUtil.isHAEnabled(conf));
return newProxyInstance(conf, protocol, instance, retryPolicy);
}
Aggregations