From 74adb11f4c504abbb6a52de72b53883ad7b952b4 Mon Sep 17 00:00:00 2001 From: tedyu Date: Fri, 23 Jan 2015 09:43:01 -0800 Subject: [PATCH] HBASE-10499 In write heavy scenario one of the regions does not get flushed causing RegionTooBusyException (Ram and Ted) --- .../hbase/regionserver/MemStoreFlusher.java | 15 +++++++++++---- .../hbase/regionserver/TestFlushRegionEntry.java | 5 +++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MemStoreFlusher.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MemStoreFlusher.java index a345a05e64d..e5ad5908cb8 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MemStoreFlusher.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MemStoreFlusher.java @@ -619,7 +619,8 @@ class MemStoreFlusher implements FlushRequester { return this.globalMemStoreLimit; } - interface FlushQueueEntry extends Delayed {} + interface FlushQueueEntry extends Delayed { + } /** * Token to insert into the flush queue that ensures that the flusher does not sleep @@ -639,7 +640,6 @@ class MemStoreFlusher implements FlushRequester { public boolean equals(Object obj) { return (this == obj); } - } /** @@ -709,8 +709,14 @@ class MemStoreFlusher implements FlushRequester { @Override public int compareTo(Delayed other) { - return Long.valueOf(getDelay(TimeUnit.MILLISECONDS) - + // Delay is compared first. If there is a tie, compare region's hash code + int ret = Long.valueOf(getDelay(TimeUnit.MILLISECONDS) - other.getDelay(TimeUnit.MILLISECONDS)).intValue(); + if (ret != 0) { + return ret; + } + FlushQueueEntry otherEntry = (FlushQueueEntry) other; + return hashCode() - otherEntry.hashCode(); } @Override @@ -720,7 +726,8 @@ class MemStoreFlusher implements FlushRequester { @Override public int hashCode() { - return (int) getDelay(TimeUnit.MILLISECONDS); + int hash = (int) getDelay(TimeUnit.MILLISECONDS); + return hash ^ region.hashCode(); } @Override diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFlushRegionEntry.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFlushRegionEntry.java index 676885b61ed..bd50f5912d6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFlushRegionEntry.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFlushRegionEntry.java @@ -34,8 +34,9 @@ public class TestFlushRegionEntry { @Test public void test() { - FlushRegionEntry entry = new FlushRegionEntry(Mockito.mock(HRegion.class), true); - FlushRegionEntry other = new FlushRegionEntry(Mockito.mock(HRegion.class), true); + HRegion r = Mockito.mock(HRegion.class); + FlushRegionEntry entry = new FlushRegionEntry(r, true); + FlushRegionEntry other = new FlushRegionEntry(r, true); assertEquals(entry.hashCode(), other.hashCode()); assertEquals(entry, other);