This is an automated email from the ASF dual-hosted git repository.
eshu11 pushed a commit to branch feature/GEODE-6517
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/feature/GEODE-6517 by this
push:
new 6751717 GEODE-6517: Fix a race by counting down the latch.
6751717 is described below
commit 6751717585dd3a6405578013f0d1bea5f289d8e6
Author: eshu <[email protected]>
AuthorDate: Tue Mar 12 17:06:44 2019 -0700
GEODE-6517: Fix a race by counting down the latch.
---
.../internal/cache/PRHARedundancyProvider.java | 36 ++++++----
.../internal/cache/PRHARedundancyProviderTest.java | 79 ++++++++++++++++++++++
2 files changed, 103 insertions(+), 12 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 d8f9c57..5676ce4 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
@@ -1707,21 +1707,12 @@ public class PRHARedundancyProvider {
ArrayList<ProxyBucketRegion> bucketsHostedLocally =
new ArrayList<ProxyBucketRegion>(proxyBucketArray.length);
+ allBucketsRecoveredFromDisk = new CountDownLatch(proxyBucketArray.length);
+
/*
* Start the redundancy logger before recovering any proxy buckets.
*/
- allBucketsRecoveredFromDisk = new CountDownLatch(proxyBucketArray.length);
- try {
- if (proxyBucketArray.length > 0) {
- this.redundancyLogger = new RedundancyLogger(this);
- Thread loggingThread = new LoggingThread(
- "RedundancyLogger for region " + this.prRegion.getName(), false,
this.redundancyLogger);
- loggingThread.start();
- }
- } catch (RuntimeException e) {
- allBucketsRecoveredFromDisk = null;
- throw e;
- }
+ startRedundancyLogger(proxyBucketArray.length);
/*
* Spawn a separate thread for bucket that we previously hosted to recover
that bucket.
@@ -1793,6 +1784,27 @@ public class PRHARedundancyProvider {
// }
}
+ void startRedundancyLogger(int proxyBuckets) {
+ try {
+ if (proxyBuckets > 0) {
+ redundancyLogger = createRedundancyLogger();
+ Thread loggingThread = new LoggingThread(
+ "RedundancyLogger for region " + this.prRegion.getName(), false,
this.redundancyLogger);
+ loggingThread.start();
+ }
+ } catch (RuntimeException e) {
+ for (int i = 0; i < proxyBuckets; i++) {
+ allBucketsRecoveredFromDisk.countDown();
+ }
+ allBucketsRecoveredFromDisk = null;
+ throw e;
+ }
+ }
+
+ RedundancyLogger createRedundancyLogger() {
+ return new RedundancyLogger(this);
+ }
+
/**
* Check to see if any colocated region of the current region is persistent.
It's not enough to
* check just the leader region, because a child region might be a
persistent parallel WAN queue,
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
new file mode 100644
index 0000000..febf589
--- /dev/null
+++
b/geode-core/src/test/java/org/apache/geode/internal/cache/PRHARedundancyProviderTest.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express
+ * or implied. See the License for the specific language governing permissions
and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import java.util.concurrent.CountDownLatch;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.geode.cache.CacheClosedException;
+
+public class PRHARedundancyProviderTest {
+ private PRHARedundancyProvider provider;
+ private final int numberOfBuckets = 113;
+ private CacheClosedException expected;
+
+ @Before
+ public void setup() {
+ PartitionedRegion partitionedRegion = mock(PartitionedRegion.class,
RETURNS_DEEP_STUBS);
+ provider = spy(new PRHARedundancyProvider(partitionedRegion));
+ }
+
+ @Test
+ public void
waitForPersistentBucketRecoveryProceedsIfStartRedundancyLoggerThrows()
+ throws Exception {
+ provider.allBucketsRecoveredFromDisk = new CountDownLatch(numberOfBuckets);
+ doThrow(new
CacheClosedException()).when(provider).createRedundancyLogger();
+
+ Thread thread = new Thread(() -> startRedundancyLogger());
+ thread.start();
+
+ provider.waitForPersistentBucketRecovery();
+ thread.join();
+
+ assertThat(expected).isNotNull();
+ }
+
+ private void startRedundancyLogger() {
+ try {
+ provider.startRedundancyLogger(numberOfBuckets);
+ } catch (CacheClosedException e) {
+ expected = e;
+ }
+ }
+
+ @Test
+ public void
waitForPersistentBucketRecoveryProceedsWhenAllBucketsRecoveredFromDiskLatchIsNull()
{
+ provider.waitForPersistentBucketRecovery();
+ }
+
+ @Test
+ public void waitForPersistentBucketRecoveryProceedsAfterLatchCountDown()
throws Exception {
+ provider.allBucketsRecoveredFromDisk = spy(new CountDownLatch(1));
+ provider.allBucketsRecoveredFromDisk.countDown();
+
+ provider.waitForPersistentBucketRecovery();
+
+ verify(provider.allBucketsRecoveredFromDisk).await();
+ }
+}