Quellcode durchsuchen

MAPREDUCE-4765. Restarting the JobTracker programmatically can cause DelegationTokenRenewal to throw an exception. (rkanter via tucu)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-1@1406810 13f79535-47bb-0310-9956-ffa450edef68
Alejandro Abdelnur vor 12 Jahren
Ursprung
Commit
525c5f75cb

+ 3 - 0
CHANGES.txt

@@ -311,6 +311,9 @@ Release 1.2.0 - unreleased
     directory deletion completes. It allows other operations when the 
     deletion is in progress. (umamahesh via suresh)
 
+    MAPREDUCE-4765. Restarting the JobTracker programmatically can cause
+    DelegationTokenRenewal to throw an exception. (rkanter via tucu)
+
 Release 1.1.1 - Unreleased
 
   INCOMPATIBLE CHANGES

+ 10 - 4
src/mapred/org/apache/hadoop/mapreduce/security/token/DelegationTokenRenewal.java

@@ -89,7 +89,7 @@ public class DelegationTokenRenewal {
   }
   
   // global single timer (daemon)
-  private static Timer renewalTimer = new Timer(true);
+  private static Timer renewalTimer = null;
   
   //delegation token canceler thread
   private static DelegationTokenCancelThread dtCancelThread =
@@ -232,7 +232,7 @@ public class DelegationTokenRenewal {
   /**
    * set task to renew the token
    */
-  private static 
+  private static synchronized
   void setTimerForTokenRenewal(DelegationTokenToRenew token, 
                                boolean firstTime) throws IOException {
       
@@ -250,14 +250,20 @@ public class DelegationTokenRenewal {
     TimerTask tTask = new RenewalTimerTask(token);
     token.setTimerTask(tTask); // keep reference to the timer
 
+    if (renewalTimer == null) {
+        renewalTimer = new Timer(true);
+    }
     renewalTimer.schedule(token.timerTask, new Date(renewIn));
   }
 
   /**
    * removing all tokens renewals
    */
-  static public void close() {
-    renewalTimer.cancel();
+  public static synchronized void close() {
+    if (renewalTimer != null) {
+        renewalTimer.cancel();
+    }
+    renewalTimer = null;
     delegationTokens.clear();
   }
   

+ 15 - 0
src/test/org/apache/hadoop/mapreduce/security/token/TestDelegationTokenRenewal.java

@@ -354,4 +354,19 @@ public class TestDelegationTokenRenewal {
       //expected
     }
   }
+
+  /**
+   * Run the testDTRenewal(), close the DelegationTokenRenewal, and run the
+   * testDTRenewal() test again to make sure that DelegationTokenRenewal can be
+   * re-used after its been closed
+   * @throws Exception
+   */
+  @Test
+  public void testDTRenewalAfterClose() throws Exception {
+      Renewer.counter = 0;
+      testDTRenewal();
+      DelegationTokenRenewal.close();
+      Renewer.counter = 0;
+      testDTRenewal();
+  }
 }