geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject incubator-geode git commit: fix race if OffHeapMemoryMonitor.updateMemoryUsed Also fixed test to use standard locators for connectivity instead of an mcast-port.
Date Wed, 18 Nov 2015 01:23:02 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-438 [created] 04afd82bc


fix race if OffHeapMemoryMonitor.updateMemoryUsed
Also fixed test to use standard locators for connectivity
instead of an mcast-port.


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

Branch: refs/heads/feature/GEODE-438
Commit: 04afd82bc10eb92dffbb8a0af7301b9b683e947e
Parents: 90b9a63
Author: Darrel Schneider <dschneider@pivotal.io>
Authored: Tue Nov 17 17:20:59 2015 -0800
Committer: Darrel Schneider <dschneider@pivotal.io>
Committed: Tue Nov 17 17:20:59 2015 -0800

----------------------------------------------------------------------
 .../cache/control/OffHeapMemoryMonitor.java       | 18 +++++++++++++++---
 .../MemoryThresholdsOffHeapDUnitTest.java         | 17 ++++++++++-------
 2 files changed, 25 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/04afd82b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/control/OffHeapMemoryMonitor.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/control/OffHeapMemoryMonitor.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/control/OffHeapMemoryMonitor.java
index 721e9a6..b2b56dc 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/control/OffHeapMemoryMonitor.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/control/OffHeapMemoryMonitor.java
@@ -58,9 +58,9 @@ public class OffHeapMemoryMonitor implements ResourceMonitor, MemoryUsageListene
   // Set to true when setEvictionThreshold(...) is called.
   private boolean hasEvictionThreshold = false;
 
-  private OffHeapMemoryUsageListener offHeapMemoryUsageListener;
   private Thread memoryListenerThread;
   
+  private final OffHeapMemoryUsageListener offHeapMemoryUsageListener;
   private final InternalResourceManager resourceManager;
   private final ResourceAdvisor resourceAdvisor;
   private final GemFireCacheImpl cache;
@@ -80,6 +80,7 @@ public class OffHeapMemoryMonitor implements ResourceMonitor, MemoryUsageListene
     }
     
     this.log = cache.getLoggerI18n();
+    this.offHeapMemoryUsageListener = new OffHeapMemoryUsageListener(0L);
   }
 
   /**
@@ -92,7 +93,7 @@ public class OffHeapMemoryMonitor implements ResourceMonitor, MemoryUsageListene
         return;
       }
 
-      this.offHeapMemoryUsageListener = new OffHeapMemoryUsageListener(getBytesUsed());
+      this.offHeapMemoryUsageListener.offHeapMemoryUsed = getBytesUsed();
       ThreadGroup group = LoggingThreadGroup.createThreadGroup("OffHeapMemoryMonitor Threads",
logger);
       Thread t = new Thread(group, this.offHeapMemoryUsageListener);
       t.setName(t.getName() + " OffHeapMemoryListener");
@@ -342,6 +343,14 @@ public class OffHeapMemoryMonitor implements ResourceMonitor, MemoryUsageListene
    * @return true if a new event might need to be sent
    */
   private boolean mightSendEvent(long bytesUsed) {
+    if (this.offHeapMemoryUsageListener.offHeapMemoryUsed != bytesUsed) {
+      // fix for GEODE-438
+      return true;
+    }
+    // We do the following if the memory is the same just in case
+    // corner cases exist in which even though the amount of memory
+    // has not changed the we might have a different state.
+    // It is possible that the following code is not needed.
     final MemoryEvent mre = this.mostRecentEvent;
     final MemoryState oldState = mre.getState();
     final MemoryThresholds thresholds = this.thresholds;
@@ -497,7 +506,10 @@ public class OffHeapMemoryMonitor implements ResourceMonitor, MemoryUsageListene
   
   class OffHeapMemoryUsageListener implements Runnable {
     volatile boolean stopRequested = false;
-    long offHeapMemoryUsed; // In bytes
+    /**
+     * volatile so that mightSendEvent can check it w/o syncing
+     */
+    volatile long offHeapMemoryUsed; // In bytes
     
     OffHeapMemoryUsageListener(final long offHeapMemoryUsed) {
       this.offHeapMemoryUsed = offHeapMemoryUsed;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/04afd82b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/management/MemoryThresholdsOffHeapDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache/management/MemoryThresholdsOffHeapDUnitTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/management/MemoryThresholdsOffHeapDUnitTest.java
index a6f24d0..5399d28 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache/management/MemoryThresholdsOffHeapDUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/management/MemoryThresholdsOffHeapDUnitTest.java
@@ -524,7 +524,6 @@ public class MemoryThresholdsOffHeapDUnitTest extends ClientServerTestCase
{
     final VM replicate1 = host.getVM(1);
     final VM replicate2 = host.getVM(2);
     final String rName = getUniqueName();
-    final int mcastPort = AvailablePortHelper.getRandomAvailableUDPPort();
     
     // Make sure the desired VMs will have a fresh DS.
     AsyncInvocation d1 = replicate1.invokeAsync(DistributedTestCase.class, "disconnectFromDS");
@@ -537,7 +536,7 @@ public class MemoryThresholdsOffHeapDUnitTest extends ClientServerTestCase
{
       @SuppressWarnings("synthetic-access")
       @Override
       public void run2() throws CacheException {
-        getSystem(getServerProperties(mcastPort));
+        getSystem(getOffHeapProperties());
       }
     };
     replicate1.invoke(establishConnectivity);
@@ -547,7 +546,7 @@ public class MemoryThresholdsOffHeapDUnitTest extends ClientServerTestCase
{
       @Override
       public void run2() throws CacheException {
         // Assert some level of connectivity
-        InternalDistributedSystem ds = getSystem(getServerProperties(mcastPort));
+        InternalDistributedSystem ds = getSystem(getOffHeapProperties());
         assertTrue(ds.getDistributionManager().getNormalDistributionManagerIds().size() >=
1);
 
         InternalResourceManager irm = (InternalResourceManager)getCache().getResourceManager();
@@ -1156,14 +1155,13 @@ public class MemoryThresholdsOffHeapDUnitTest extends ClientServerTestCase
{
     final Host host = Host.getHost(0);
     final VM vm = host.getVM(2);
     final String rName = getUniqueName();
-    final int mcastPort = AvailablePortHelper.getRandomAvailableUDPPort();
 
     vm.invoke(DistributedTestCase.class, "disconnectFromDS");
     
     vm.invoke(new CacheSerializableRunnable("test LocalRegion load passthrough when critical")
{
       @Override
       public void run2() throws CacheException {
-        getSystem(getServerProperties(mcastPort));
+        getSystem(getOffHeapProperties());
         InternalResourceManager irm = (InternalResourceManager)getCache().getResourceManager();
         final OffHeapMemoryMonitor ohmm = irm.getOffHeapMonitor();
         irm.setCriticalOffHeapPercentage(90f);
@@ -1821,12 +1819,17 @@ public class MemoryThresholdsOffHeapDUnitTest extends ClientServerTestCase
{
     });
   }
   
-  private Properties getServerProperties(int mcastPort) {
+  private Properties getOffHeapProperties() {
     Properties p = new Properties();
+    p.setProperty(DistributionConfig.OFF_HEAP_MEMORY_SIZE_NAME, "1m");
+    return p;
+  }
+
+  private Properties getServerProperties(int mcastPort) {
+    Properties p = getOffHeapProperties();
     p.setProperty(DistributionConfig.MCAST_PORT_NAME, mcastPort + "");
     p.setProperty(DistributionConfig.MCAST_TTL_NAME, "0");
     p.setProperty(DistributionConfig.LOCATORS_NAME, "");
-    p.setProperty(DistributionConfig.OFF_HEAP_MEMORY_SIZE_NAME, "1m");
     return p;
   }
   


Mime
View raw message