Просмотр исходного кода

HADOOP-11122. Fix findbugs in ZK DelegationTokenSecretManagers. (Arun Suresh via kasha)

Karthik Kambatla 10 лет назад
Родитель
Сommit
70719e5c62

+ 3 - 0
hadoop-common-project/hadoop-common/CHANGES.txt

@@ -994,6 +994,9 @@ Release 2.6.0 - UNRELEASED
     HADOOP-11175. Fix several issues of hadoop security configuration in user
     doc. (Yi Liu via cnauroth)
 
+    HADOOP-11122. Fix findbugs in ZK DelegationTokenSecretManagers.
+    (Arun Suresh via kasha)
+
 Release 2.5.1 - 2014-09-05
 
   INCOMPATIBLE CHANGES

+ 3 - 9
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/AbstractDelegationTokenSecretManager.java

@@ -163,11 +163,6 @@ extends AbstractDelegationTokenIdentifier>
     return;
   }
 
-  // for ZK based secretManager
-  protected void updateMasterKey(DelegationKey key) throws IOException{
-    return;
-  }
-
   // RM
   protected void removeStoredMasterKey(DelegationKey key) {
     return;
@@ -191,7 +186,7 @@ extends AbstractDelegationTokenIdentifier>
    * For subclasses externalizing the storage, for example Zookeeper
    * based implementations
    */
-  protected int getDelegationTokenSeqNum() {
+  protected synchronized int getDelegationTokenSeqNum() {
     return delegationTokenSequenceNumber;
   }
 
@@ -199,7 +194,7 @@ extends AbstractDelegationTokenIdentifier>
    * For subclasses externalizing the storage, for example Zookeeper
    * based implementations
    */
-  protected int incrementDelegationTokenSeqNum() {
+  protected synchronized int incrementDelegationTokenSeqNum() {
     return ++delegationTokenSequenceNumber;
   }
 
@@ -207,7 +202,7 @@ extends AbstractDelegationTokenIdentifier>
    * For subclasses externalizing the storage, for example Zookeeper
    * based implementations
    */
-  protected void setDelegationTokenSeqNum(int seqNum) {
+  protected synchronized void setDelegationTokenSeqNum(int seqNum) {
     delegationTokenSequenceNumber = seqNum;
   }
 
@@ -234,7 +229,6 @@ extends AbstractDelegationTokenIdentifier>
    */
   protected void updateDelegationKey(DelegationKey key) throws IOException {
     allKeys.put(key.getKeyId(), key);
-    updateMasterKey(key);
   }
 
   /**

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

@@ -276,7 +276,7 @@ public abstract class ZKDelegationTokenSecretManager<TokenIdent extends Abstract
   }
 
   @Override
-  public void startThreads() throws IOException {
+  public synchronized void startThreads() throws IOException {
     if (!isExternalClient) {
       try {
         zkClient.start();
@@ -402,7 +402,7 @@ public abstract class ZKDelegationTokenSecretManager<TokenIdent extends Abstract
   }
 
   @Override
-  public void stopThreads() {
+  public synchronized void stopThreads() {
     try {
       if (!isExternalClient && (zkClient != null)) {
         zkClient.close();
@@ -434,12 +434,12 @@ public abstract class ZKDelegationTokenSecretManager<TokenIdent extends Abstract
   }
 
   @Override
-  protected int getDelegationTokenSeqNum() {
+  protected synchronized int getDelegationTokenSeqNum() {
     return seqCounter.getCount();
   }
 
   @Override
-  protected int incrementDelegationTokenSeqNum() {
+  protected synchronized int incrementDelegationTokenSeqNum() {
     try {
       while (!seqCounter.trySetCount(seqCounter.getCount() + 1)) {
       }
@@ -450,8 +450,12 @@ public abstract class ZKDelegationTokenSecretManager<TokenIdent extends Abstract
   }
 
   @Override
-  protected void setDelegationTokenSeqNum(int seqNum) {
-    delegationTokenSequenceNumber = seqNum;
+  protected synchronized void setDelegationTokenSeqNum(int seqNum) {
+    try {
+      seqCounter.setCount(seqNum);
+    } catch (Exception e) {
+      throw new RuntimeException("Could not set shared counter !!", e);
+    }
   }
 
   @Override