This is an automated email from the ASF dual-hosted git repository.
dschneider pushed a commit to branch support/1.15
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/support/1.15 by this push:
new c6848d9578 GEODE-10328: close data store stats on cache close (#7716)
c6848d9578 is described below
commit c6848d9578719b7a001ba8b94f4ab70f478fdc16
Author: Darrel Schneider <[email protected]>
AuthorDate: Mon May 23 13:57:04 2022 -0700
GEODE-10328: close data store stats on cache close (#7716)
data store stats are now also closed on cache close or forced disconnect
(cherry picked from commit b89fc2ca2fe094a1344828d1e128db04273dcdfd)
---
.../geode/internal/cache/PartitionedRegion.java | 45 +++++++++++++++++++---
.../internal/cache/PartitionedRegionTest.java | 22 ++++++++++-
2 files changed, 61 insertions(+), 6 deletions(-)
diff --git
a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
index c5d59d6e55..f75ad9d2c2 100755
---
a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
+++
b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
@@ -771,6 +771,10 @@ public class PartitionedRegion extends LocalRegion
private boolean regionCreationNotified;
+ public interface RegionAdvisorFactory {
+ RegionAdvisor create(PartitionedRegion region);
+ }
+
/**
* Constructor for a PartitionedRegion. This has an accessor (Region API)
functionality and
* contains a datastore for actual storage. An accessor can act as a local
cache by having a local
@@ -784,6 +788,20 @@ public class PartitionedRegion extends LocalRegion
InternalRegionArguments internalRegionArgs,
StatisticsClock statisticsClock,
ColocationLoggerFactory colocationLoggerFactory) {
+ this(regionName, regionAttributes, parentRegion, cache,
internalRegionArgs, statisticsClock,
+ colocationLoggerFactory,
+ region -> RegionAdvisor.createRegionAdvisor(region));
+ }
+
+ PartitionedRegion(String regionName,
+ RegionAttributes regionAttributes,
+ LocalRegion parentRegion,
+ InternalCache cache,
+ InternalRegionArguments internalRegionArgs,
+ StatisticsClock statisticsClock,
+ ColocationLoggerFactory colocationLoggerFactory,
+ RegionAdvisorFactory regionAdvisorFactory) {
+
super(regionName, regionAttributes, parentRegion, cache,
internalRegionArgs,
new PartitionedRegionDataView(), statisticsClock);
@@ -811,7 +829,7 @@ public class PartitionedRegion extends LocalRegion
prStats.incTotalNumBuckets(totalNumberOfBuckets);
// Warning: potential early escape of instance
- distAdvisor = RegionAdvisor.createRegionAdvisor(this);
+ distAdvisor = regionAdvisorFactory.create(this);
senderIdMonitor = createSenderIdMonitor();
// Warning: potential early escape of instance
redundancyProvider = new PRHARedundancyProvider(this,
cache.getInternalResourceManager());
@@ -1371,10 +1389,13 @@ public class PartitionedRegion extends LocalRegion
* @param ra Region attributes
*/
private void initializeDataStore(RegionAttributes ra) {
-
- dataStore =
+ setDataStore(
PartitionedRegionDataStore.createDataStore(cache, this,
ra.getPartitionAttributes(),
- getStatisticsClock());
+ getStatisticsClock()));
+ }
+
+ void setDataStore(PartitionedRegionDataStore dataStore) {
+ this.dataStore = dataStore;
}
protected DistributedLockService getPartitionedRegionLockService() {
@@ -7079,7 +7100,7 @@ public class PartitionedRegion extends LocalRegion
private void closePartitionedRegion(RegionEventImpl event) {
final boolean isClose = event.getOperation().isClose();
if (isClose) {
- isClosed = true;
+ setClosed();
}
final RegionLock rl = getRegionLock();
try {
@@ -7127,6 +7148,10 @@ public class PartitionedRegion extends LocalRegion
new Object[] {getFullPath(), getPRId()});
}
+ void setClosed() {
+ isClosed = true;
+ }
+
public void checkForColocatedChildren() {
List<PartitionedRegion> listOfChildRegions =
ColocationHelper.getColocatedChildRegions(this);
if (listOfChildRegions.size() != 0) {
@@ -7690,6 +7715,7 @@ public class PartitionedRegion extends LocalRegion
if (dsi != null && dsi.getOwnedByRegion()) {
cache.addDiskStore(dsi);
}
+ closeDataStoreStats();
}
// Majority of cache close operations handled by
@@ -7767,6 +7793,15 @@ public class PartitionedRegion extends LocalRegion
cache.getInternalDistributedSystem().getDistributedMember(), null,
op.isClose());
}
+ private void closeDataStoreStats() {
+ if (dataStore != null) {
+ CachePerfStats dataStoreStats = dataStore.getCachePerfStats();
+ if (dataStoreStats != null) {
+ dataStoreStats.close();
+ }
+ }
+ }
+
/**
* This method checks whether this PartitionedRegion is eligible for the
destruction or not. It
* first gets the prConfig for this region, and if it NULL, it sends a
diff --git
a/geode-core/src/test/java/org/apache/geode/internal/cache/PartitionedRegionTest.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/PartitionedRegionTest.java
index 01ed9c66b7..b50e74b32c 100644
---
a/geode-core/src/test/java/org/apache/geode/internal/cache/PartitionedRegionTest.java
+++
b/geode-core/src/test/java/org/apache/geode/internal/cache/PartitionedRegionTest.java
@@ -23,6 +23,7 @@ import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
@@ -82,6 +83,7 @@ import
org.apache.geode.distributed.internal.DistributionManager;
import org.apache.geode.distributed.internal.InternalDistributedSystem;
import
org.apache.geode.distributed.internal.membership.InternalDistributedMember;
import org.apache.geode.internal.cache.control.InternalResourceManager;
+import org.apache.geode.internal.cache.partitioned.RegionAdvisor;
import
org.apache.geode.internal.cache.partitioned.colocation.ColocationLoggerFactory;
import org.apache.geode.test.junit.runners.GeodeParamsRunner;
@@ -134,7 +136,8 @@ public class PartitionedRegionTest {
partitionedRegion = new PartitionedRegion("regionName",
attributesFactory.create(), null,
cache, mock(InternalRegionArguments.class), disabledClock(),
- ColocationLoggerFactory.create());
+ ColocationLoggerFactory.create(),
+ region -> mock(RegionAdvisor.class));
}
private Object[] cacheLoaderAndWriter() {
@@ -148,6 +151,23 @@ public class PartitionedRegionTest {
};
}
+ @Test
+ public void postDestroyRegionForCacheCloseWillCloseDataStoreStats() {
+ PartitionedRegionDataStore dataStore =
mock(PartitionedRegionDataStore.class);
+ CachePerfStats dataStoreStats = mock(CachePerfStats.class);
+ when(dataStore.getCachePerfStats()).thenReturn(dataStoreStats);
+ partitionedRegion.setDataStore(dataStore);
+ partitionedRegion.setClosed();
+ when(cache.getInternalResourceManager(anyBoolean()))
+ .thenReturn(mock(InternalResourceManager.class));
+ RegionEventImpl event = mock(RegionEventImpl.class);
+ when(event.getOperation()).thenReturn(Operation.CACHE_CLOSE);
+
+ partitionedRegion.postDestroyRegion(false, event);
+
+ verify(dataStoreStats).close();
+ }
+
@Test
@Parameters(method = "cacheLoaderAndWriter")
@TestCaseName("{method}(CacheLoader={0}, CacheWriter={1})")