diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 0ab397eae6a..22fdc784a67 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -1942,10 +1942,12 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi /** * Should the memstore be flushed now */ - boolean shouldFlush() { + boolean shouldFlush(final StringBuffer whyFlush) { + whyFlush.setLength(0); // This is a rough measure. if (this.maxFlushedSeqId > 0 && (this.maxFlushedSeqId + this.flushPerChanges < this.sequenceId.get())) { + whyFlush.append("more than max edits, " + this.flushPerChanges + ", since last flush"); return true; } long modifiedFlushCheckInterval = flushCheckInterval; @@ -1966,6 +1968,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi for (Store s : getStores()) { if (s.timeOfOldestEdit() < now - modifiedFlushCheckInterval) { // we have an old enough edit in the memstore, flush + whyFlush.append(s.toString() + " has an old edit so flush to free WALs"); return true; } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index 9e3af90ea87..843c0a7ab30 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -1548,15 +1548,17 @@ public class HRegionServer extends HasThread implements @Override protected void chore() { + final StringBuffer whyFlush = new StringBuffer(); for (Region r : this.server.onlineRegions.values()) { - if (r == null) - continue; - if (((HRegion)r).shouldFlush()) { + if (r == null) continue; + if (((HRegion)r).shouldFlush(whyFlush)) { FlushRequester requester = server.getFlushRequester(); if (requester != null) { long randomDelay = RandomUtils.nextInt(RANGE_OF_DELAY) + MIN_DELAY_TIME; - LOG.info(getName() + " requesting flush for region " + - r.getRegionInfo().getRegionNameAsString() + " after a delay of " + randomDelay); + LOG.info(getName() + " requesting flush of " + + r.getRegionInfo().getRegionNameAsString() + " because " + + whyFlush.toString() + + " after random delay " + randomDelay + "ms"); //Throttle the flushes by putting a delay. If we don't throttle, and there //is a balanced write-load on the regions in a table, we might end up //overwhelming the filesystem with too many flushes at once. diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultMemStore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultMemStore.java index 7a405a4e0ec..d0c3b912f76 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultMemStore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultMemStore.java @@ -927,9 +927,10 @@ public class TestDefaultMemStore extends TestCase { edge.setCurrentTimeMillis(1234); s.add(KeyValueTestUtil.create("r", "f", "q", 100, "v")); edge.setCurrentTimeMillis(1234 + 100); - assertTrue(region.shouldFlush() == false); + StringBuffer sb = new StringBuffer(); + assertTrue(region.shouldFlush(sb) == false); edge.setCurrentTimeMillis(1234 + 10000); - assertTrue(region.shouldFlush() == expected); + assertTrue(region.shouldFlush(sb) == expected); } finally { EnvironmentEdgeManager.reset(); } @@ -960,9 +961,10 @@ public class TestDefaultMemStore extends TestCase { wFactory.getWAL(hri.getEncodedNameAsBytes())); HRegion.addRegionToMETA(meta, r); edge.setCurrentTimeMillis(1234 + 100); - assertTrue(meta.shouldFlush() == false); + StringBuffer sb = new StringBuffer(); + assertTrue(meta.shouldFlush(sb) == false); edge.setCurrentTimeMillis(edge.currentTime() + HRegion.META_CACHE_FLUSH_INTERVAL + 1); - assertTrue(meta.shouldFlush() == true); + assertTrue(meta.shouldFlush(sb) == true); } private class EnvironmentEdgeForMemstoreTest implements EnvironmentEdge {