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: GEODE-500: fix race in OffHeapMemoryUsageListener
Date Thu, 05 Nov 2015 01:23:11 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-500 [created] 2e9652c72


GEODE-500: fix race in OffHeapMemoryUsageListener

A race in the run loop existed that caused the usage
listener to quit delivering off-heap events.
This should fix a number of intermittent off-heap
resource manager bugs.


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

Branch: refs/heads/feature/GEODE-500
Commit: 2e9652c721d1f5c0b79e71e3c55ae989ddced444
Parents: 8c4e749
Author: Darrel Schneider <dschneider@pivotal.io>
Authored: Wed Nov 4 17:20:42 2015 -0800
Committer: Darrel Schneider <dschneider@pivotal.io>
Committed: Wed Nov 4 17:20:42 2015 -0800

----------------------------------------------------------------------
 .../cache/control/OffHeapMemoryMonitor.java        | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/2e9652c7/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 bbdb27a..0a6674c 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
@@ -511,11 +511,20 @@ public class OffHeapMemoryMonitor implements ResourceMonitor, MemoryUsageListene
         updateStateAndSendEvent(lastOffHeapMemoryUsed);
 
         synchronized (this) {
-          if (lastOffHeapMemoryUsed == this.offHeapMemoryUsed && !this.stopRequested)
{
-            try {
+          long newOffHeapMemoryUsed = this.offHeapMemoryUsed;
+          if (this.stopRequested) {
+            // no need to wait since we are stopping
+          } else if (lastOffHeapMemoryUsed != newOffHeapMemoryUsed) {
+            // no need to wait since memory used has changed
+            // This fixes a race like bug GEODE-500
+            lastOffHeapMemoryUsed = newOffHeapMemoryUsed;
+          } else {
+            // wait for memory used to change
+            try {  
               do {
                 this.wait(1000);
-                if (this.offHeapMemoryUsed == lastOffHeapMemoryUsed) {
+                newOffHeapMemoryUsed = this.offHeapMemoryUsed;
+                if (newOffHeapMemoryUsed == lastOffHeapMemoryUsed) {
                   // The wait timed out. So tell the OffHeapMemoryMonitor
                   // that we need an event if the state is not normal.
                   deliverNextAbnormalEvent();
@@ -536,7 +545,7 @@ public class OffHeapMemoryMonitor implements ResourceMonitor, MemoryUsageListene
                 } else {
                   // we have been notified so exit the inner while loop
                   // and call updateStateAndSendEvent.
-                  lastOffHeapMemoryUsed = this.offHeapMemoryUsed;
+                  lastOffHeapMemoryUsed = newOffHeapMemoryUsed;
                   break;
                 }
               } while (!this.stopRequested);


Mime
View raw message