You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bo...@apache.org on 2021/01/20 19:59:08 UTC

[geode] branch develop updated: GEODE-8827: Modified LocalRegion.initializeStats to increment bytesOnlyOnDisk

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

boglesby pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 5c6546b  GEODE-8827: Modified LocalRegion.initializeStats to increment bytesOnlyOnDisk
5c6546b is described below

commit 5c6546be40ea96f04ea976fc71b1cf41d2272773
Author: Barry Oglesby <bo...@users.noreply.github.com>
AuthorDate: Wed Jan 20 09:58:03 2021 -1000

    GEODE-8827: Modified LocalRegion.initializeStats to increment bytesOnlyOnDisk
---
 .../cache/PersistentRegionRecoveryDUnitTest.java   | 40 ++++++++++++++++++++++
 .../apache/geode/internal/cache/LocalRegion.java   |  1 +
 .../geode/internal/cache/LocalRegionTest.java      | 25 ++++++++++++++
 3 files changed, 66 insertions(+)

diff --git a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/PersistentRegionRecoveryDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/PersistentRegionRecoveryDUnitTest.java
index 77f2006..3cfd680 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/PersistentRegionRecoveryDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/PersistentRegionRecoveryDUnitTest.java
@@ -23,6 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import java.io.File;
 import java.io.IOException;
 import java.io.Serializable;
+import java.util.stream.IntStream;
 
 import org.apache.logging.log4j.Logger;
 import org.junit.After;
@@ -44,6 +45,7 @@ import org.apache.geode.test.dunit.IgnoredException;
 import org.apache.geode.test.dunit.VM;
 import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
 import org.apache.geode.test.dunit.rules.CacheRule;
+import org.apache.geode.test.dunit.rules.DistributedRestoreSystemProperties;
 import org.apache.geode.test.dunit.rules.DistributedRule;
 import org.apache.geode.test.junit.rules.serializable.SerializableTemporaryFolder;
 import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
@@ -70,6 +72,10 @@ public class PersistentRegionRecoveryDUnitTest extends JUnit4DistributedTestCase
   @Rule
   public SerializableTestName testName = new SerializableTestName();
 
+  @Rule
+  public DistributedRestoreSystemProperties restoreSystemProperties =
+      new DistributedRestoreSystemProperties();
+
   @Before
   public void setUp() throws Exception {
     vm0 = getVM(0);
@@ -461,6 +467,40 @@ public class PersistentRegionRecoveryDUnitTest extends JUnit4DistributedTestCase
     });
   }
 
+  @Test
+  public void verifyPersistentRecoveryIncrementsNumOverflowBytesOnDisk() {
+    // Create cache and persistent region
+    vm0.invoke(() -> createSyncDiskRegion());
+
+    // Add entries
+    int numEntries = 10;
+    int entrySize = 10240;
+    vm0.invoke(() -> putEntries(numEntries, entrySize));
+
+    // Close cache
+    vm0.invoke(() -> cacheRule.closeAndNullCache());
+
+    // Recreate cache and persistent region without recovering values
+    vm0.invoke(() -> {
+      System.setProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME, "false");
+      createSyncDiskRegion();
+    });
+
+    // Verify numOverflowBytesOnDisk is set after recovery
+    vm0.invoke(() -> verifyNumOverflowBytesOnDiskSet(numEntries, entrySize));
+  }
+
+  private void putEntries(int numEntries, int entrySize) {
+    Region region = cacheRule.getCache().getRegion(regionName);
+    IntStream.range(0, numEntries).forEach(i -> region.put(i, new byte[entrySize]));
+  }
+
+  private void verifyNumOverflowBytesOnDiskSet(int numEntries, int entrySize) {
+    LocalRegion region = (LocalRegion) cacheRule.getCache().getRegion(regionName);
+    assertThat(region.getDiskRegion().getStats().getNumOverflowBytesOnDisk())
+        .isEqualTo(numEntries * entrySize);
+  }
+
   private void flushAsyncDiskRegion() {
     for (DiskStore store : cacheRule.getCache().listDiskStoresIncludingRegionOwned()) {
       ((DiskStoreImpl) store).forceFlush();
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
index 61328f3..96b2738 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
@@ -10219,6 +10219,7 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
       long numOverflowBytesOnDisk) {
     getDiskRegion().getStats().incNumEntriesInVM(numEntriesInVM);
     getDiskRegion().getStats().incNumOverflowOnDisk(numOverflowOnDisk);
+    getDiskRegion().getStats().incNumOverflowBytesOnDisk(numOverflowBytesOnDisk);
   }
 
   /**
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/LocalRegionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/LocalRegionTest.java
index dd9cce1..44599be 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/LocalRegionTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/LocalRegionTest.java
@@ -277,4 +277,29 @@ public class LocalRegionTest {
 
     assertThat(region.isGenerateLocalFilterRoutingNeeded(event)).isFalse();
   }
+
+  @Test
+  public void initializeStatsInvokesDiskRegionStatsMethods() {
+    LocalRegion region =
+        spy(new LocalRegion("region", regionAttributes, null, cache, internalRegionArguments,
+            internalDataView, regionMapConstructor, serverRegionProxyConstructor, entryEventFactory,
+            poolFinder, regionPerfStatsFactory, disabledClock()));
+
+    // Mock DiskRegion and DiskRegionStats
+    DiskRegion dr = mock(DiskRegion.class);
+    when(region.getDiskRegion()).thenReturn(dr);
+    DiskRegionStats drs = mock(DiskRegionStats.class);
+    when(dr.getStats()).thenReturn(drs);
+
+    // Invoke initializeStats
+    int numEntriesInVM = 100;
+    long numOverflowOnDisk = 200l;
+    long numOverflowBytesOnDisk = 300l;
+    region.initializeStats(numEntriesInVM, numOverflowOnDisk, numOverflowBytesOnDisk);
+
+    // Verify the DiskRegionStats methods were invoked
+    verify(drs).incNumEntriesInVM(numEntriesInVM);
+    verify(drs).incNumOverflowOnDisk(numOverflowOnDisk);
+    verify(drs).incNumOverflowBytesOnDisk(numOverflowBytesOnDisk);
+  }
 }