Explorar o código

HADOOP-18824. ZKDelegationTokenSecretManager causes ArithmeticException due to improper numRetries value checking (#6052)

ConfX hai 1 ano
pai
achega
23360b3f6b

+ 1 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/ZKDelegationTokenSecretManager.java

@@ -222,7 +222,7 @@ public abstract class ZKDelegationTokenSecretManager<TokenIdent extends Abstract
                         ZK_DTSM_ZK_CONNECTION_TIMEOUT_DEFAULT)
                 )
                 .retryPolicy(
-                    new RetryNTimes(numRetries, sessionT / numRetries));
+                    new RetryNTimes(numRetries, numRetries == 0 ? 0 : sessionT / numRetries));
       } catch (Exception ex) {
         throw new RuntimeException("Could not Load ZK acls or auth: " + ex, ex);
       }

+ 12 - 0
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/delegation/TestZKDelegationTokenSecretManager.java

@@ -106,10 +106,22 @@ public class TestZKDelegationTokenSecretManager {
   @SuppressWarnings("unchecked")
   @Test
   public void testMultiNodeOperations() throws Exception {
+      testMultiNodeOperationsImpl(false);
+  }
+
+  @Test
+  public void testMultiNodeOperationsWithZeroRetry() throws Exception {
+      testMultiNodeOperationsImpl(true);
+  }
+
+  public void testMultiNodeOperationsImpl(boolean setZeroRetry) throws Exception {
     for (int i = 0; i < TEST_RETRIES; i++) {
       DelegationTokenManager tm1, tm2 = null;
       String connectString = zkServer.getConnectString();
       Configuration conf = getSecretConf(connectString);
+      if (setZeroRetry) {
+          conf.setInt(ZKDelegationTokenSecretManager.ZK_DTSM_ZK_NUM_RETRIES, 0);
+      }
       tm1 = new DelegationTokenManager(conf, new Text("bla"));
       tm1.init();
       tm2 = new DelegationTokenManager(conf, new Text("bla"));