diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java index 2b72fd3cbff..f1e4cb76727 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java @@ -171,15 +171,13 @@ public class AssignmentManager extends ZooKeeperListener { private final ExecutorService executorService; // For unit tests, keep track of calls to ClosedRegionHandler - private Map closedRegionHandlerCalled = - new HashMap(); + private Map closedRegionHandlerCalled = null; // For unit tests, keep track of calls to OpenedRegionHandler - private Map openedRegionHandlerCalled = - new HashMap(); + private Map openedRegionHandlerCalled = null; // For unit tests, keep track of calls to SplitRegionHandler - private AtomicBoolean splitRegionHandlerCalled = new AtomicBoolean(false); + private AtomicBoolean splitRegionHandlerCalled = null; //Thread pool executor service for timeout monitor private java.util.concurrent.ExecutorService threadPoolExecutorService; @@ -883,7 +881,7 @@ public class AssignmentManager extends ZooKeeperListener { } // Run handler to do the rest of the SPLIT handling. new SplitRegionHandler(server, this, regionState.getRegion(), sn, daughters).process(); - splitRegionHandlerCalled.set(true); + updateSplitHandlerTracker(); break; case RS_ZK_REGION_MERGING: @@ -951,7 +949,7 @@ public class AssignmentManager extends ZooKeeperListener { if (regionState != null) { removeClosedRegion(regionState.getRegion()); new ClosedRegionHandler(server, this, regionState.getRegion()).process(); - closedRegionHandlerCalled.put(regionState.getRegion(), new AtomicBoolean(true)); + updateClosedRegionHandlerTracker(regionState.getRegion()); } break; @@ -1026,7 +1024,7 @@ public class AssignmentManager extends ZooKeeperListener { failedOpenTracker.remove(encodedName); // reset the count, if any new OpenedRegionHandler( server, this, regionState.getRegion(), sn, expectedVersion).process(); - openedRegionHandlerCalled.put(regionState.getRegion(), new AtomicBoolean(true)); + updateOpenedRegionHandlerTracker(regionState.getRegion()); } break; @@ -1064,6 +1062,31 @@ public class AssignmentManager extends ZooKeeperListener { return splitRegionHandlerCalled.compareAndSet(true, false); } + //For unit tests only + void initializeHandlerTrackers() { + closedRegionHandlerCalled = new HashMap(); + openedRegionHandlerCalled = new HashMap(); + splitRegionHandlerCalled = new AtomicBoolean(false); + } + + void updateClosedRegionHandlerTracker(HRegionInfo hri) { + if (closedRegionHandlerCalled != null) { //only for unit tests this is true + closedRegionHandlerCalled.put(hri, new AtomicBoolean(true)); + } + } + + void updateOpenedRegionHandlerTracker(HRegionInfo hri) { + if (openedRegionHandlerCalled != null) { //only for unit tests this is true + openedRegionHandlerCalled.put(hri, new AtomicBoolean(true)); + } + } + + void updateSplitHandlerTracker() { + if (splitRegionHandlerCalled != null) { //only for unit tests this is true + splitRegionHandlerCalled.set(true); + } + } + /** * @return Returns true if this RegionState is splittable; i.e. the * RegionState is currently in splitting state or pending_close or diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java index f4efe5ecb14..0bc3d4eef42 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java @@ -53,6 +53,7 @@ public class TestMaster { // Start a cluster of two regionservers. TEST_UTIL.startMiniCluster(2); admin = TEST_UTIL.getHBaseAdmin(); + TEST_UTIL.getHBaseCluster().getMaster().assignmentManager.initializeHandlerTrackers(); } @AfterClass diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestZKBasedOpenCloseRegion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestZKBasedOpenCloseRegion.java index ad7af067499..a16a4b27be9 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestZKBasedOpenCloseRegion.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestZKBasedOpenCloseRegion.java @@ -80,6 +80,7 @@ public class TestZKBasedOpenCloseRegion { waitUntilAllRegionsAssigned(); addToEachStartKey(countOfRegions); t.close(); + TEST_UTIL.getHBaseCluster().getMaster().assignmentManager.initializeHandlerTrackers(); } @AfterClass public static void afterAllTests() throws Exception {