diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index c297270bf15..1d11f8fa5d5 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -846,6 +846,16 @@ public class HRegion implements HeapSize { // , Writable{ return this.closing.get(); } + /** @return true if region is available (not closed and not closing) */ + public boolean isAvailable() { + return !isClosed() && !isClosing(); + } + + /** @return true if region is splittable */ + public boolean isSplittable() { + return isAvailable() && !hasReferences(); + } + boolean areWritesEnabled() { synchronized(this.writestate) { return this.writestate.writesEnabled; diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index 9c215b456bb..3e6d0cd5baa 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -1914,8 +1914,7 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, try { for (Map.Entry e: this.onlineRegions.entrySet()) { HRegion r = e.getValue(); - if (!r.getRegionInfo().isMetaRegion()) { - if (r.isClosed() || r.isClosing()) continue; + if (!r.getRegionInfo().isMetaRegion() && r.isAvailable()) { // Don't update zk with this close transition; pass false. closeRegion(r.getRegionInfo(), abort, false); } @@ -3135,7 +3134,7 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, protected HRegionInfo[] getMostLoadedRegions() { ArrayList regions = new ArrayList(); for (HRegion r : onlineRegions.values()) { - if (r.isClosed() || r.isClosing()) { + if (!r.isAvailable()) { continue; } if (regions.size() < numRegionsToReport) { diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/SplitTransaction.java b/src/main/java/org/apache/hadoop/hbase/regionserver/SplitTransaction.java index 03f0e518311..71948b2371a 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/SplitTransaction.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/SplitTransaction.java @@ -163,7 +163,7 @@ public class SplitTransaction { * false if it is not (e.g. its already closed, etc.). */ public boolean prepare() { - if (this.parent.isClosed() || this.parent.isClosing()) return false; + if (!this.parent.isSplittable()) return false; // Split key can be null if this region is unsplittable; i.e. has refs. if (this.splitrow == null) return false; HRegionInfo hri = this.parent.getRegionInfo(); diff --git a/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransaction.java b/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransaction.java index 8dc3d0c05e0..1de88277c2e 100644 --- a/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransaction.java +++ b/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransaction.java @@ -19,6 +19,8 @@ */ package org.apache.hadoop.hbase.regionserver; +import com.google.common.collect.ImmutableList; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -137,6 +139,28 @@ public class TestSplitTransaction { return st; } + /** + * Pass a reference store + */ + @Test public void testPrepareWithRegionsWithReference() throws IOException { + // create a mock that will act as a reference StoreFile + StoreFile storeFileMock = Mockito.mock(StoreFile.class); + when(storeFileMock.isReference()).thenReturn(true); + + // add the mock to the parent stores + Store storeMock = Mockito.mock(Store.class); + List storeFileList = new ArrayList(1); + storeFileList.add(storeFileMock); + when(storeMock.getStorefiles()).thenReturn(storeFileList); + when(storeMock.close()).thenReturn(ImmutableList.copyOf(storeFileList)); + this.parent.stores.put(Bytes.toBytes(""), storeMock); + + SplitTransaction st = new SplitTransaction(this.parent, GOOD_SPLIT_ROW); + + assertFalse("a region should not be splittable if it has instances of store file references", + st.prepare()); + } + /** * Pass an unreasonable split row. */