You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2017/04/19 20:28:14 UTC

[2/2] geode git commit: 2632: fix up getCache synchronization in AutoBalancer

2632: fix up getCache synchronization in AutoBalancer


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/08106d33
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/08106d33
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/08106d33

Branch: refs/heads/feature/GEODE-2632-4
Commit: 08106d3305c8b3179e2e6a9055754a5452d5080f
Parents: c44cc06
Author: Kirk Lund <kl...@apache.org>
Authored: Wed Apr 19 13:26:36 2017 -0700
Committer: Kirk Lund <kl...@apache.org>
Committed: Wed Apr 19 13:26:36 2017 -0700

----------------------------------------------------------------------
 .../apache/geode/cache/util/AutoBalancer.java   | 21 ++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/08106d33/geode-rebalancer/src/main/java/org/apache/geode/cache/util/AutoBalancer.java
----------------------------------------------------------------------
diff --git a/geode-rebalancer/src/main/java/org/apache/geode/cache/util/AutoBalancer.java b/geode-rebalancer/src/main/java/org/apache/geode/cache/util/AutoBalancer.java
index ab8b5b0..2965f7f 100644
--- a/geode-rebalancer/src/main/java/org/apache/geode/cache/util/AutoBalancer.java
+++ b/geode-rebalancer/src/main/java/org/apache/geode/cache/util/AutoBalancer.java
@@ -25,12 +25,13 @@ import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
 
-import org.apache.geode.annotations.Experimental;
 import org.apache.logging.log4j.Logger;
 import org.springframework.scheduling.support.CronSequenceGenerator;
 
 import org.apache.geode.GemFireConfigException;
+import org.apache.geode.annotations.Experimental;
 import org.apache.geode.cache.CacheClosedException;
 import org.apache.geode.cache.Declarable;
 import org.apache.geode.cache.GemFireCache;
@@ -344,14 +345,14 @@ public class AutoBalancer implements Declarable {
   static class GeodeCacheFacade implements CacheOperationFacade {
     private final AtomicBoolean isLockAcquired = new AtomicBoolean(false);
 
-    private InternalCache cache;
+    private final AtomicReference<InternalCache> cacheRef = new AtomicReference();
 
     public GeodeCacheFacade() {
       this(null);
     }
 
     public GeodeCacheFacade(InternalCache cache) {
-      this.cache = cache;
+      this.cacheRef.set(cache);
     }
 
     @Override
@@ -443,16 +444,16 @@ public class AutoBalancer implements Declarable {
     }
 
     InternalCache getCache() {
-      if (cache == null) {
+      if (cacheRef.get() == null) {
         synchronized (this) {
-          if (cache == null) {
-            cache = GemFireCacheImpl.getInstance();
-            if (cache == null) {
-              throw new IllegalStateException("Missing cache instance.");
-            }
-          }
+          cacheRef.set(GemFireCacheImpl.getInstance());
         }
       }
+
+      InternalCache cache = cacheRef.get();
+      if (cache == null) {
+        throw new IllegalStateException("Missing cache instance.");
+      }
       if (cache.isClosed()) {
         throw new CacheClosedException();
       }