Search in sources :

Example 11 with RetryPolicy

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);
}
Also used : RetryPolicy(org.apache.hadoop.io.retry.RetryPolicy) TestConnectionRetryPolicy(org.apache.hadoop.io.retry.TestConnectionRetryPolicy) Test(org.junit.Test)

Example 12 with RetryPolicy

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);
}
Also used : RetryPolicy(org.apache.hadoop.io.retry.RetryPolicy) Date(java.util.Date) Test(org.junit.Test)

Example 13 with RetryPolicy

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);
    }
}
Also used : HashMap(java.util.HashMap) NamenodeProtocolTranslatorPB(org.apache.hadoop.hdfs.protocolPB.NamenodeProtocolTranslatorPB) NamenodeProtocolPB(org.apache.hadoop.hdfs.protocolPB.NamenodeProtocolPB) RetryPolicy(org.apache.hadoop.io.retry.RetryPolicy) NamenodeProtocol(org.apache.hadoop.hdfs.server.protocol.NamenodeProtocol)

Example 14 with RetryPolicy

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);
}
Also used : YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) RetryPolicy(org.apache.hadoop.io.retry.RetryPolicy) Private(org.apache.hadoop.classification.InterfaceAudience.Private)

Aggregations

RetryPolicy (org.apache.hadoop.io.retry.RetryPolicy)14 HashMap (java.util.HashMap)5 EOFException (java.io.EOFException)4 IOException (java.io.IOException)4 SocketException (java.net.SocketException)3 RetriableException (org.apache.hadoop.ipc.RetriableException)3 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)3 Test (org.junit.Test)3 ConnectException (java.net.ConnectException)2 NoRouteToHostException (java.net.NoRouteToHostException)2 UnknownHostException (java.net.UnknownHostException)2 Private (org.apache.hadoop.classification.InterfaceAudience.Private)2 TestConnectionRetryPolicy (org.apache.hadoop.io.retry.TestConnectionRetryPolicy)2 ConnectTimeoutException (org.apache.hadoop.net.ConnectTimeoutException)2 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketTimeoutException (java.net.SocketTimeoutException)1 URISyntaxException (java.net.URISyntaxException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1