hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ecl...@apache.org
Subject hbase git commit: HBASE-14742 Fix TestHeapMemoryManager being flakey
Date Tue, 03 Nov 2015 01:12:03 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 2e1711f20 -> b24324cc2


HBASE-14742 Fix TestHeapMemoryManager being flakey


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/b24324cc
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/b24324cc
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/b24324cc

Branch: refs/heads/branch-1
Commit: b24324cc23da6b41aea8339a6fee68a148b160e8
Parents: 2e1711f
Author: Elliott Clark <eclark@apache.org>
Authored: Mon Nov 2 09:50:48 2015 -0800
Committer: Elliott Clark <eclark@apache.org>
Committed: Mon Nov 2 17:02:41 2015 -0800

----------------------------------------------------------------------
 .../regionserver/TestHeapMemoryManager.java     | 59 +++++++++++++++-----
 1 file changed, 45 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/b24324cc/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHeapMemoryManager.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHeapMemoryManager.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHeapMemoryManager.java
index 9cbde84..99acf0f 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHeapMemoryManager.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHeapMemoryManager.java
@@ -30,10 +30,12 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.ChoreService;
 import org.apache.hadoop.hbase.CoordinatedStateManager;
 import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.Server;
 import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.Waiter;
 import org.apache.hadoop.hbase.client.ClusterConnection;
 import org.apache.hadoop.hbase.io.hfile.BlockCache;
 import org.apache.hadoop.hbase.io.hfile.BlockCacheKey;
@@ -52,6 +54,8 @@ import org.junit.experimental.categories.Category;
 @Category(SmallTests.class)
 public class TestHeapMemoryManager {
 
+  private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
+
   private long maxHeapSize = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax();
 
   @Test
@@ -128,7 +132,8 @@ public class TestHeapMemoryManager {
     memStoreFlusher.requestFlush(null, false);
     memStoreFlusher.flushType = FlushType.ABOVE_LOWER_MARK;
     memStoreFlusher.requestFlush(null, false);
-    Thread.sleep(1500); // Allow the tuner to run once and do necessary memory up
+    // Allow the tuner to run once and do necessary memory up
+    Thread.sleep(1500);
     // No changes should be made by tuner as we already have lot of empty space
     assertEquals(oldMemstoreHeapSize, memStoreFlusher.memstoreSize);
     assertEquals(oldBlockCacheSize, blockCache.maxSize);
@@ -159,7 +164,8 @@ public class TestHeapMemoryManager {
     blockCache.evictBlock(null);
     blockCache.evictBlock(null);
     blockCache.evictBlock(null);
-    Thread.sleep(1500); // Allow the tuner to run once and do necessary memory up
+    // Allow the tuner to run once and do necessary memory up
+    Thread.sleep(1500);
     // No changes should be made by tuner as we already have lot of empty space
     assertEquals(oldMemstoreHeapSize, memStoreFlusher.memstoreSize);
     assertEquals(oldBlockCacheSize, blockCache.maxSize);
@@ -192,7 +198,8 @@ public class TestHeapMemoryManager {
     memStoreFlusher.requestFlush(null, false);
     memStoreFlusher.requestFlush(null, false);
     memStoreFlusher.requestFlush(null, false);
-    Thread.sleep(1500); // Allow the tuner to run once and do necessary memory up
+    // Allow the tuner to run once and do necessary memory up
+    waitForTune(memStoreFlusher, memStoreFlusher.memstoreSize);
     assertHeapSpaceDelta(DefaultHeapMemoryTuner.DEFAULT_MAX_STEP_VALUE, oldMemstoreHeapSize,
         memStoreFlusher.memstoreSize);
     assertHeapSpaceDelta(-(DefaultHeapMemoryTuner.DEFAULT_MAX_STEP_VALUE), oldBlockCacheSize,
@@ -203,7 +210,8 @@ public class TestHeapMemoryManager {
     memStoreFlusher.flushType = FlushType.ABOVE_LOWER_MARK;
     memStoreFlusher.requestFlush(null, false);
     memStoreFlusher.requestFlush(null, false);
-    Thread.sleep(1500);
+    // Allow the tuner to run once and do necessary memory up
+    waitForTune(memStoreFlusher, memStoreFlusher.memstoreSize);
     assertHeapSpaceDelta(DefaultHeapMemoryTuner.DEFAULT_MAX_STEP_VALUE, oldMemstoreHeapSize,
         memStoreFlusher.memstoreSize);
     assertHeapSpaceDelta(-(DefaultHeapMemoryTuner.DEFAULT_MAX_STEP_VALUE), oldBlockCacheSize,
@@ -235,7 +243,8 @@ public class TestHeapMemoryManager {
     blockCache.evictBlock(null);
     blockCache.evictBlock(null);
     blockCache.evictBlock(null);
-    Thread.sleep(1500); // Allow the tuner to run once and do necessary memory up
+    // Allow the tuner to run once and do necessary memory up
+    waitForTune(memStoreFlusher, memStoreFlusher.memstoreSize);
     assertHeapSpaceDelta(-(DefaultHeapMemoryTuner.DEFAULT_MAX_STEP_VALUE), oldMemstoreHeapSize,
         memStoreFlusher.memstoreSize);
     assertHeapSpaceDelta(DefaultHeapMemoryTuner.DEFAULT_MAX_STEP_VALUE, oldBlockCacheSize,
@@ -244,7 +253,8 @@ public class TestHeapMemoryManager {
     oldBlockCacheSize = blockCache.maxSize;
     // Do some more evictions before the next run of HeapMemoryTuner
     blockCache.evictBlock(null);
-    Thread.sleep(1500);
+    // Allow the tuner to run once and do necessary memory up
+    waitForTune(memStoreFlusher, memStoreFlusher.memstoreSize);
     assertHeapSpaceDelta(-(DefaultHeapMemoryTuner.DEFAULT_MAX_STEP_VALUE), oldMemstoreHeapSize,
         memStoreFlusher.memstoreSize);
     assertHeapSpaceDelta(DefaultHeapMemoryTuner.DEFAULT_MAX_STEP_VALUE, oldBlockCacheSize,
@@ -279,7 +289,8 @@ public class TestHeapMemoryManager {
     memStoreFlusher.requestFlush(null, false);
     memStoreFlusher.requestFlush(null, false);
     blockCache.evictBlock(null);
-    Thread.sleep(1500); // Allow the tuner to run once and do necessary memory up
+    // Allow the tuner to run once and do necessary memory up
+    Thread.sleep(1500);
     // No changes should happen as there is undefined increase in flushes and evictions
     assertEquals(oldMemstoreHeapSize, memStoreFlusher.memstoreSize);
     assertEquals(oldBlockCacheSize, blockCache.maxSize);
@@ -288,7 +299,8 @@ public class TestHeapMemoryManager {
     memStoreFlusher.requestFlush(null, false);
     memStoreFlusher.requestFlush(null, false);
     memStoreFlusher.requestFlush(null, false);
-    Thread.sleep(1500);
+    // Allow the tuner to run once and do necessary memory up
+    waitForTune(memStoreFlusher, memStoreFlusher.memstoreSize);
     assertHeapSpaceDelta(DefaultHeapMemoryTuner.DEFAULT_MAX_STEP_VALUE, oldMemstoreHeapSize,
         memStoreFlusher.memstoreSize);
     assertHeapSpaceDelta(-(DefaultHeapMemoryTuner.DEFAULT_MAX_STEP_VALUE), oldBlockCacheSize,
@@ -324,7 +336,8 @@ public class TestHeapMemoryManager {
     memStoreFlusher.requestFlush(null, false);
     blockCache.evictBlock(null);
     blockCache.evictBlock(null);
-    Thread.sleep(1500); // Allow the tuner to run once and do necessary memory up
+    // Allow the tuner to run once and do necessary memory up
+    Thread.sleep(1500);
     // No changes should happen as there is undefined increase in flushes and evictions
     assertEquals(oldMemstoreHeapSize, memStoreFlusher.memstoreSize);
     assertEquals(oldBlockCacheSize, blockCache.maxSize);
@@ -335,6 +348,7 @@ public class TestHeapMemoryManager {
     blockCache.evictBlock(null);
     blockCache.evictBlock(null);
     blockCache.evictBlock(null);
+    // Allow the tuner to run once and do necessary memory up
     Thread.sleep(1500);
     assertHeapSpaceDelta(DefaultHeapMemoryTuner.DEFAULT_MAX_STEP_VALUE, oldMemstoreHeapSize,
         memStoreFlusher.memstoreSize);
@@ -363,13 +377,15 @@ public class TestHeapMemoryManager {
     // Now we wants to be in write mode. Set bigger memstore size from CustomHeapMemoryTuner
     CustomHeapMemoryTuner.memstoreSize = 0.78f;
     CustomHeapMemoryTuner.blockCacheSize = 0.02f;
-    Thread.sleep(1500); // Allow the tuner to run once and do necessary memory up
+    // Allow the tuner to run once and do necessary memory up
+    waitForTune(memStoreFlusher, memStoreFlusher.memstoreSize);
     assertHeapSpace(0.78f, memStoreFlusher.memstoreSize);// Memstore
     assertHeapSpace(0.02f, blockCache.maxSize);// BlockCache
     // Now we wants to be in read mode. Set bigger memstore size from CustomHeapMemoryTuner
     CustomHeapMemoryTuner.blockCacheSize = 0.75f;
     CustomHeapMemoryTuner.memstoreSize = 0.05f;
-    Thread.sleep(1500); // Allow the tuner to run once and do necessary memory up
+    // Allow the tuner to run once and do necessary memory up
+    waitForTune(memStoreFlusher, memStoreFlusher.memstoreSize);
     assertHeapSpace(0.75f, blockCache.maxSize);// BlockCache
     assertHeapSpace(0.05f, memStoreFlusher.memstoreSize);// Memstore
   }
@@ -421,6 +437,7 @@ public class TestHeapMemoryManager {
     heapMemoryManager.start(choreService);
     CustomHeapMemoryTuner.memstoreSize = 0.7f;
     CustomHeapMemoryTuner.blockCacheSize = 0.3f;
+    // Allow the tuner to run once and do necessary memory up
     Thread.sleep(1500);
     assertEquals(oldMemstoreSize, memStoreFlusher.memstoreSize);
     assertEquals(oldBlockCacheSize, blockCache.maxSize);
@@ -464,14 +481,16 @@ public class TestHeapMemoryManager {
     heapMemoryManager.start(choreService);
     CustomHeapMemoryTuner.memstoreSize = 0.4f;
     CustomHeapMemoryTuner.blockCacheSize = 0.4f;
-    Thread.sleep(1500);
+    // Allow the tuner to run once and do necessary memory up
+   Thread.sleep(1500);
     // The size should not get changes as the collection of memstore size and L1 and L2 block
cache
     // size will cross the ax allowed 80% mark
     assertEquals(oldMemstoreSize, memStoreFlusher.memstoreSize);
     assertEquals(oldBlockCacheSize, blockCache.maxSize);
     CustomHeapMemoryTuner.memstoreSize = 0.1f;
     CustomHeapMemoryTuner.blockCacheSize = 0.5f;
-    Thread.sleep(1500);
+    // Allow the tuner to run once and do necessary memory up
+    waitForTune(memStoreFlusher, memStoreFlusher.memstoreSize);
     assertHeapSpace(0.1f, memStoreFlusher.memstoreSize);
     assertHeapSpace(0.5f, blockCache.maxSize);
   }
@@ -484,7 +503,7 @@ public class TestHeapMemoryManager {
   private void assertHeapSpaceDelta(double expectedDeltaPercent, long oldHeapSpace, long
newHeapSpace) {
     double expctedMinDelta = (double) (this.maxHeapSize * expectedDeltaPercent);
     // Tolerable error
-    double error = 0.999;
+    double error = 0.95;
     if (expectedDeltaPercent > 0) {
       assertTrue(expctedMinDelta*error <= (double)(newHeapSpace - oldHeapSpace));
       assertTrue(expctedMinDelta/error >= (double)(newHeapSpace - oldHeapSpace));
@@ -494,6 +513,18 @@ public class TestHeapMemoryManager {
     }
   }
 
+
+  private void waitForTune(final MemstoreFlusherStub memStoreFlusher,
+                           final long oldMemstoreHeapSize) throws Exception {
+    // Allow the tuner to run once and do necessary memory up
+    UTIL.waitFor(10000, new Waiter.Predicate<Exception>() {
+      @Override
+      public boolean evaluate() throws Exception {
+        return oldMemstoreHeapSize != memStoreFlusher.memstoreSize;
+      }
+    });
+  }
+
   private static class BlockCacheStub implements ResizableBlockCache {
     CacheStats stats = new CacheStats("test");
     long maxSize = 0;


Mime
View raw message