Repository: geode
Updated Branches:
  refs/heads/feature/GEM-1483 96c9745f9 -> 10b3af5aa


fix-3


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

Branch: refs/heads/feature/GEM-1483
Commit: 10b3af5aa9204e5e43e70a0b1548f03b70559d31
Parents: 96c9745
Author: zhouxh <[email protected]>
Authored: Mon Jun 19 23:54:06 2017 -0700
Committer: zhouxh <[email protected]>
Committed: Mon Jun 19 23:54:06 2017 -0700

----------------------------------------------------------------------
 .../cache/PartitionedRegionDataStore.java       | 49 ++++++++++++--------
 1 file changed, 30 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/10b3af5a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegionDataStore.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegionDataStore.java
 
b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegionDataStore.java
index 95dff75..37667a7 100644
--- 
a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegionDataStore.java
+++ 
b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegionDataStore.java
@@ -1420,26 +1420,32 @@ public class PartitionedRegionDataStore implements 
HasCachePerfStats {
   public boolean isRemotePrimaryReadyForColocatedChildren(int bucketId) {
     InternalDistributedMember myId =
         
this.partitionedRegion.getDistributionManager().getDistributionManagerId();
-    boolean isRemotePrimaryReady = true;
 
     List<PartitionedRegion> colocatedChildPRs =
         ColocationHelper.getColocatedChildRegions(this.partitionedRegion);
     if (colocatedChildPRs != null) {
       for (PartitionedRegion pr : colocatedChildPRs) {
         InternalDistributedMember primaryChild = pr.getBucketPrimary(bucketId);
+        if (logger.isDebugEnabled()) {
+          logger.debug("Checking colocated child bucket " + pr + ", bucketId=" 
+ bucketId
+              + ", primary is " + primaryChild);
+        }
         if (primaryChild == null || myId.equals(primaryChild)) {
           if (logger.isDebugEnabled()) {
             logger.debug("Colocated bucket region " + pr + " " + bucketId
                 + " does not have a remote primary yet. Not to remove.");
-            return false;
           }
+          return false;
         } else {
-          return isRemotePrimaryReady
-              && 
pr.getDataStore().isRemotePrimaryReadyForColocatedChildren(bucketId);
+          if (logger.isDebugEnabled()) {
+            logger
+                .debug(pr + " bucketId=" + bucketId + " has remove primary, 
checking its children");
+          }
+          return 
pr.getDataStore().isRemotePrimaryReadyForColocatedChildren(bucketId);
         }
       }
     }
-    return isRemotePrimaryReady;
+    return true;
   }
 
   /**
@@ -1496,17 +1502,11 @@ public class PartitionedRegionDataStore implements 
HasCachePerfStats {
 
       }
 
+      PartitionedRegion leader = 
ColocationHelper.getLeaderRegion(this.partitionedRegion);
+      boolean isLeader = leader.equals(this.partitionedRegion);
       BucketAdvisor bucketAdvisor = bucketRegion.getBucketAdvisor();
-      InternalDistributedMember primary = bucketAdvisor.getPrimary();
       InternalDistributedMember myId =
           
this.partitionedRegion.getDistributionManager().getDistributionManagerId();
-      if (primary == null || myId.equals(primary)) {
-        if (logger.isDebugEnabled()) {
-          logger.debug("Bucket region " + bucketRegion
-              + " does not have a remote primary yet. Not to remove.");
-        }
-        return false;
-      }
       Lock writeLock = bucketAdvisor.getActiveWriteLock();
 
       // Fix for 43613 - don't remove the bucket
@@ -1519,12 +1519,23 @@ public class PartitionedRegionDataStore implements 
HasCachePerfStats {
           return false;
         }
 
-        if (!isRemotePrimaryReadyForColocatedChildren(bucketId)) {
-          return false;
-        }
+        if (isLeader) {
+          if (!isRemotePrimaryReadyForColocatedChildren(bucketId)) {
+            return false;
+          }
 
-        if (logger.isDebugEnabled()) {
-          logger.debug("Bucket region " + bucketRegion + " has primary at " + 
primary);
+          InternalDistributedMember primary = bucketAdvisor.getPrimary();
+          if (primary == null || myId.equals(primary)) {
+            if (logger.isDebugEnabled()) {
+              logger.debug("Bucket region " + bucketRegion
+                  + " does not have a remote primary yet. Not to remove.");
+            }
+            return false;
+          }
+
+          if (logger.isDebugEnabled()) {
+            logger.debug("Bucket region " + bucketRegion + " has primary at " 
+ primary);
+          }
         }
 
         // recurse down to each tier of children to remove first
@@ -1555,7 +1566,7 @@ public class PartitionedRegionDataStore implements 
HasCachePerfStats {
       // wait for in progress writes. I choose to use the StateFlushOperation
       // because it won't block write operations while we're trying to acquire
       // the activePrimaryMoveLock
-      primary = bucketAdvisor.getPrimary();
+      InternalDistributedMember primary = bucketAdvisor.getPrimary();
       if (!myId.equals(primary)) {
         StateFlushOperation flush = new StateFlushOperation(bucketRegion);
         int executor = DistributionManager.WAITING_POOL_EXECUTOR;

Reply via email to