Repository: accumulo
Updated Branches:
  refs/heads/1.7 4815ec45a -> 3289940fb
  refs/heads/master e88f64235 -> fe97d5111


ACCUMULO-3876 Synchronize read on currentKey and initialized


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/3289940f
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/3289940f
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/3289940f

Branch: refs/heads/1.7
Commit: 3289940fb3c16b5374e3385bb0815994a59f99d8
Parents: 4815ec4
Author: Josh Elser <els...@apache.org>
Authored: Sun May 31 21:55:55 2015 -0400
Committer: Josh Elser <els...@apache.org>
Committed: Mon Jun 1 01:40:35 2015 -0400

----------------------------------------------------------------------
 .../delegation/AuthenticationTokenSecretManager.java |  5 ++++-
 .../delegation/ZooAuthenticationKeyDistributor.java  | 15 ++++++++-------
 2 files changed, 12 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/3289940f/server/base/src/main/java/org/apache/accumulo/server/security/delegation/AuthenticationTokenSecretManager.java
----------------------------------------------------------------------
diff --git 
a/server/base/src/main/java/org/apache/accumulo/server/security/delegation/AuthenticationTokenSecretManager.java
 
b/server/base/src/main/java/org/apache/accumulo/server/security/delegation/AuthenticationTokenSecretManager.java
index a52b5f4..66f9cdc 100644
--- 
a/server/base/src/main/java/org/apache/accumulo/server/security/delegation/AuthenticationTokenSecretManager.java
+++ 
b/server/base/src/main/java/org/apache/accumulo/server/security/delegation/AuthenticationTokenSecretManager.java
@@ -81,7 +81,10 @@ public class AuthenticationTokenSecretManager extends 
SecretManager<Authenticati
     DelegationTokenConfig cfg = identifier.getConfig();
 
     long now = System.currentTimeMillis();
-    final AuthenticationKey secretKey = currentKey;
+    final AuthenticationKey secretKey;
+    synchronized (this) {
+      secretKey = currentKey;
+    }
     identifier.setKeyId(secretKey.getKeyId());
     identifier.setIssueDate(now);
     long expiration = now + tokenMaxLifetime;

http://git-wip-us.apache.org/repos/asf/accumulo/blob/3289940f/server/base/src/main/java/org/apache/accumulo/server/security/delegation/ZooAuthenticationKeyDistributor.java
----------------------------------------------------------------------
diff --git 
a/server/base/src/main/java/org/apache/accumulo/server/security/delegation/ZooAuthenticationKeyDistributor.java
 
b/server/base/src/main/java/org/apache/accumulo/server/security/delegation/ZooAuthenticationKeyDistributor.java
index b327a26..0542596 100644
--- 
a/server/base/src/main/java/org/apache/accumulo/server/security/delegation/ZooAuthenticationKeyDistributor.java
+++ 
b/server/base/src/main/java/org/apache/accumulo/server/security/delegation/ZooAuthenticationKeyDistributor.java
@@ -27,6 +27,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.accumulo.fate.zookeeper.ZooUtil;
 import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeExistsPolicy;
@@ -46,7 +47,7 @@ public class ZooAuthenticationKeyDistributor {
 
   private final ZooReaderWriter zk;
   private final String baseNode;
-  private boolean initialized = false;
+  private AtomicBoolean initialized = new AtomicBoolean(false);
 
   public ZooAuthenticationKeyDistributor(ZooReaderWriter zk, String baseNode) {
     checkNotNull(zk);
@@ -59,7 +60,7 @@ public class ZooAuthenticationKeyDistributor {
    * Ensures that ZooKeeper is in a correct state to perform distribution of 
{@link AuthenticationKey}s.
    */
   public synchronized void initialize() throws KeeperException, 
InterruptedException {
-    if (initialized) {
+    if (initialized.get()) {
       return;
     }
 
@@ -74,7 +75,7 @@ public class ZooAuthenticationKeyDistributor {
         Id actualId = actualAcl.getId();
         // The expected outcome from ZooUtil.PRIVATE
         if (actualAcl.getPerms() == expectedAcl.getPerms() && 
actualId.getScheme().equals("digest") && 
actualId.getId().startsWith("accumulo:")) {
-          initialized = true;
+          initialized.set(true);
           return;
         }
       } else {
@@ -85,7 +86,7 @@ public class ZooAuthenticationKeyDistributor {
       throw new IllegalStateException("Delegation token secret key node in 
ZooKeeper is not protected.");
     }
 
-    initialized = true;
+    initialized.set(true);
   }
 
   /**
@@ -94,7 +95,7 @@ public class ZooAuthenticationKeyDistributor {
    * @return A list of {@link AuthenticationKey}s
    */
   public List<AuthenticationKey> getCurrentKeys() throws KeeperException, 
InterruptedException {
-    checkState(initialized, "Not initialized");
+    checkState(initialized.get(), "Not initialized");
     List<String> children = zk.getChildren(baseNode);
 
     // Shortcircuit to avoid a list creation
@@ -127,7 +128,7 @@ public class ZooAuthenticationKeyDistributor {
    *          The key to add to ZooKeeper
    */
   public synchronized void advertise(AuthenticationKey newKey) throws 
KeeperException, InterruptedException {
-    checkState(initialized, "Not initialized");
+    checkState(initialized.get(), "Not initialized");
     checkNotNull(newKey);
 
     // Make sure the node doesn't already exist
@@ -161,7 +162,7 @@ public class ZooAuthenticationKeyDistributor {
    *          The key to remove from ZooKeeper
    */
   public synchronized void remove(AuthenticationKey key) throws 
KeeperException, InterruptedException {
-    checkState(initialized, "Not initialized");
+    checkState(initialized.get(), "Not initialized");
     checkNotNull(key);
 
     String path = qualifyPath(key);

Reply via email to