You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by gj...@apache.org on 2019/04/26 22:28:32 UTC

[phoenix] branch 4.x-HBase-1.2 updated: PHOENIX-5251: Avoid taking explicit lock by using AtomicReference in PhoenixAccessController class

This is an automated email from the ASF dual-hosted git repository.

gjacoby pushed a commit to branch 4.x-HBase-1.2
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/4.x-HBase-1.2 by this push:
     new 72d8520  PHOENIX-5251: Avoid taking explicit lock by using AtomicReference in PhoenixAccessController class
72d8520 is described below

commit 72d8520393949ab7fd902c15cdfe0c120c59b206
Author: s.kadam <s....@salesforce.com>
AuthorDate: Mon Apr 22 15:24:45 2019 -0700

    PHOENIX-5251: Avoid taking explicit lock by using AtomicReference in PhoenixAccessController class
    
    Signed-off-by: Geoffrey Jacoby <gj...@apache.org>
---
 .../coprocessor/PhoenixAccessController.java       | 26 ++++++++++------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/PhoenixAccessController.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/PhoenixAccessController.java
index befa87d..2872e12 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/PhoenixAccessController.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/PhoenixAccessController.java
@@ -25,6 +25,7 @@ import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
 
 import com.google.protobuf.ByteString;
 import org.apache.commons.logging.Log;
@@ -71,7 +72,7 @@ import com.google.protobuf.RpcCallback;
 public class PhoenixAccessController extends BaseMetaDataEndpointObserver {
 
     private PhoenixMetaDataControllerEnvironment env;
-    private volatile ArrayList<BaseMasterAndRegionObserver> accessControllers;
+    AtomicReference<ArrayList<BaseMasterAndRegionObserver>> accessControllers = new AtomicReference<>();
     private boolean accessCheckEnabled;
     private UserProvider userProvider;
     public static final Log LOG = LogFactory.getLog(PhoenixAccessController.class);
@@ -79,22 +80,19 @@ public class PhoenixAccessController extends BaseMetaDataEndpointObserver {
             LogFactory.getLog("SecurityLogger."+PhoenixAccessController.class.getName());
 
     private List<BaseMasterAndRegionObserver> getAccessControllers() throws IOException {
-        if (accessControllers == null) {
-            synchronized (this) {
-                if (accessControllers == null) {
-                    accessControllers = new ArrayList<BaseMasterAndRegionObserver>();
-                    RegionCoprocessorHost cpHost = this.env.getCoprocessorHost();
-                    List<BaseMasterAndRegionObserver> coprocessors = cpHost
-                            .findCoprocessors(BaseMasterAndRegionObserver.class);
-                    for (BaseMasterAndRegionObserver cp : coprocessors) {
-                        if (cp instanceof AccessControlService.Interface) {
-                            accessControllers.add(cp);
-                        }
-                    }
+        ArrayList<BaseMasterAndRegionObserver> oldAccessControllers = accessControllers.get();
+        if (oldAccessControllers == null) {
+            oldAccessControllers = new ArrayList<>();
+            RegionCoprocessorHost cpHost = this.env.getCoprocessorHost();
+            List<BaseMasterAndRegionObserver> coprocessors = cpHost.findCoprocessors(BaseMasterAndRegionObserver.class);
+            for (BaseMasterAndRegionObserver cp : coprocessors) {
+                if (cp instanceof AccessControlService.Interface) {
+                    oldAccessControllers.add(cp);
                 }
             }
+            accessControllers.set(oldAccessControllers);
         }
-        return accessControllers;
+        return accessControllers.get();
     }
 
     @Override