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

eshu11 pushed a commit to branch feature/GEODE-6630
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/feature/GEODE-6630 by this 
push:
     new 3c3aae8  fix a review comment.
3c3aae8 is described below

commit 3c3aae86b750b73cc3b8e84714afdaa2104c3b9c
Author: eshu <[email protected]>
AuthorDate: Wed Apr 17 16:08:45 2019 -0700

    fix a review comment.
---
 .../internal/cache/PRHARedundancyProvider.java     | 36 ++++++++--------------
 .../partitioned/PersistentBucketRecoverer.java     | 23 +++++++++++++-
 .../internal/cache/PRHARedundancyProviderTest.java | 16 +++++-----
 3 files changed, 42 insertions(+), 33 deletions(-)

diff --git 
a/geode-core/src/main/java/org/apache/geode/internal/cache/PRHARedundancyProvider.java
 
b/geode-core/src/main/java/org/apache/geode/internal/cache/PRHARedundancyProvider.java
index 7f951fb..add48cf 100644
--- 
a/geode-core/src/main/java/org/apache/geode/internal/cache/PRHARedundancyProvider.java
+++ 
b/geode-core/src/main/java/org/apache/geode/internal/cache/PRHARedundancyProvider.java
@@ -25,7 +25,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
-import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
@@ -1747,9 +1746,8 @@ public class PRHARedundancyProvider {
             try {
               super.run();
             } finally {
-              CountDownLatch recoveryLatch = getRecoveryLatch();
-              if (recoveryLatch != null) {
-                recoveryLatch.countDown();
+              if (getPersistentBucketRecoverer() != null) {
+                getPersistentBucketRecoverer().countDown();
               }
             }
           }
@@ -1782,9 +1780,8 @@ public class PRHARedundancyProvider {
       }
     } finally {
       for (final ProxyBucketRegion proxyBucket : bucketsNotHostedLocally) {
-        CountDownLatch recoveryLatch = getRecoveryLatch();
-        if (recoveryLatch != null) {
-          recoveryLatch.countDown();
+        if (getPersistentBucketRecoverer() != null) {
+          getPersistentBucketRecoverer().countDown();
         }
       }
     }
@@ -1795,11 +1792,6 @@ public class PRHARedundancyProvider {
     // }
   }
 
-  CountDownLatch getRecoveryLatch() {
-    return getPersistentBucketRecoverer() == null ? null
-        : getPersistentBucketRecoverer().getAllBucketsRecoveredFromDiskLatch();
-  }
-
   private PersistentBucketRecoverer createPersistentBucketRecoverer(int 
proxyBuckets) {
     return new PersistentBucketRecoverer(this, proxyBuckets);
   }
@@ -1996,13 +1988,12 @@ public class PRHARedundancyProvider {
    * whichever happens first.
    */
   protected void waitForPersistentBucketRecoveryOrClose() {
-    CountDownLatch recoveryLatch = getRecoveryLatch();
-    if (recoveryLatch != null) {
+    if (getPersistentBucketRecoverer() != null) {
       boolean interrupted = false;
       while (true) {
         try {
           this.prRegion.getCancelCriterion().checkCancelInProgress(null);
-          boolean done = recoveryLatch.await(
+          boolean done = getPersistentBucketRecoverer().await(
               PartitionedRegionHelper.DEFAULT_WAIT_PER_RETRY_ITERATION, 
TimeUnit.MILLISECONDS);
           if (done) {
             break;
@@ -2028,12 +2019,11 @@ public class PRHARedundancyProvider {
    * currently being closed.
    */
   protected void waitForPersistentBucketRecovery() {
-    CountDownLatch recoveryLatch = getRecoveryLatch();
-    if (recoveryLatch != null) {
+    if (getPersistentBucketRecoverer() != null) {
       boolean interrupted = false;
       while (true) {
         try {
-          recoveryLatch.await();
+          getPersistentBucketRecoverer().await();
           break;
         } catch (InterruptedException e) {
           interrupted = true;
@@ -2049,8 +2039,9 @@ public class PRHARedundancyProvider {
     if (!ColocationHelper.checkMembersColocation(this.prRegion, 
this.prRegion.getMyId())) {
       return false;
     }
-    CountDownLatch recoveryLatch = getRecoveryLatch();
-    if (recoveryLatch != null && recoveryLatch.getCount() > 0) {
+
+    if (getPersistentBucketRecoverer() != null
+        && !getPersistentBucketRecoverer().hasRecoveryCompleted()) {
       return false;
     }
 
@@ -2059,12 +2050,11 @@ public class PRHARedundancyProvider {
 
     for (PartitionedRegion region : colocatedRegions.values()) {
       PRHARedundancyProvider redundancyProvider = 
region.getRedundancyProvider();
-      recoveryLatch = redundancyProvider.getRecoveryLatch();
-      if (recoveryLatch != null && recoveryLatch.getCount() > 0) {
+      if (redundancyProvider.getPersistentBucketRecoverer() != null &&
+          
!redundancyProvider.getPersistentBucketRecoverer().hasRecoveryCompleted()) {
         return false;
       }
     }
-
     return true;
   }
 
diff --git 
a/geode-core/src/main/java/org/apache/geode/internal/cache/partitioned/PersistentBucketRecoverer.java
 
b/geode-core/src/main/java/org/apache/geode/internal/cache/partitioned/PersistentBucketRecoverer.java
index 54e2130..813517d 100644
--- 
a/geode-core/src/main/java/org/apache/geode/internal/cache/partitioned/PersistentBucketRecoverer.java
+++ 
b/geode-core/src/main/java/org/apache/geode/internal/cache/partitioned/PersistentBucketRecoverer.java
@@ -25,6 +25,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.logging.log4j.Logger;
 
@@ -407,7 +408,27 @@ public class PersistentBucketRecoverer extends 
RecoveryRunnable implements Persi
     }
   }
 
-  public CountDownLatch getAllBucketsRecoveredFromDiskLatch() {
+  public boolean await(long timeout, TimeUnit unit) throws 
InterruptedException {
+    return allBucketsRecoveredFromDisk.await(timeout, unit);
+  }
+
+  public void await() throws InterruptedException {
+    allBucketsRecoveredFromDisk.await();
+  }
+
+  public void countDown() {
+    allBucketsRecoveredFromDisk.countDown();
+  }
+
+  public boolean hasRecoveryCompleted() {
+    if (allBucketsRecoveredFromDisk.getCount() > 0) {
+      return false;
+    }
+    return true;
+  }
+
+  CountDownLatch getAllBucketsRecoveredFromDiskLatch() {
     return allBucketsRecoveredFromDisk;
   }
+
 }
diff --git 
a/geode-core/src/test/java/org/apache/geode/internal/cache/PRHARedundancyProviderTest.java
 
b/geode-core/src/test/java/org/apache/geode/internal/cache/PRHARedundancyProviderTest.java
index 2065987..c5fcff5 100644
--- 
a/geode-core/src/test/java/org/apache/geode/internal/cache/PRHARedundancyProviderTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/internal/cache/PRHARedundancyProviderTest.java
@@ -21,8 +21,6 @@ import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import java.util.concurrent.CountDownLatch;
-
 import org.junit.Before;
 import org.junit.Test;
 
@@ -35,6 +33,10 @@ public class PRHARedundancyProviderTest {
   @Before
   public void setup() {
     PartitionedRegion partitionedRegion = mock(PartitionedRegion.class, 
RETURNS_DEEP_STUBS);
+    InternalCache cache = mock(InternalCache.class);
+    DistributedRegion root = mock(DistributedRegion.class);
+    when(partitionedRegion.getCache()).thenReturn(cache);
+    when(cache.getRegion(PartitionedRegionHelper.PR_ROOT_REGION_NAME, 
true)).thenReturn(root);
     provider = spy(new PRHARedundancyProvider(partitionedRegion));
   }
 
@@ -48,16 +50,12 @@ public class PRHARedundancyProviderTest {
 
   @Test
   public void waitForPersistentBucketRecoveryProceedsAfterLatchCountDown() 
throws Exception {
-    PersistentBucketRecoverer recoverer = 
mock(PersistentBucketRecoverer.class);
+    PersistentBucketRecoverer recoverer = spy(new 
PersistentBucketRecoverer(provider, 1));
     doReturn(recoverer).when(provider).getPersistentBucketRecoverer();
-    CountDownLatch latch = spy(new CountDownLatch(1));
-    when(recoverer.getAllBucketsRecoveredFromDiskLatch()).thenReturn(latch);
-    latch.countDown();
+    provider.getPersistentBucketRecoverer().countDown();
 
     provider.waitForPersistentBucketRecovery();
 
-    verify(latch).await();
+    verify(recoverer).await();
   }
-
-
 }

Reply via email to