public boolean balance() throws IOException { return balance(false); }
boolean balanceRun = master.balance(); assertTrue("Coprocessor should be called on region rebalancing", cp.wasBalanceCalled());
@Override protected void chore() { try { master.balance(); } catch (IOException e) { LOG.error("Failed to balance.", e); } } }
@Override public BalanceResponse balance(RpcController controller, BalanceRequest request) throws ServiceException { try { return BalanceResponse.newBuilder().setBalancerRan(master.balance( request.hasForce()? request.getForce(): false)).build(); } catch (IOException ex) { throw new ServiceException(ex); } }
@Test public void testThrottlingByBalanceInterval() throws Exception { // Use default config and start a cluster of two regionservers. TEST_UTIL.startMiniCluster(2); TableName tableName = createTable("testNoThrottling"); final HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); // Default max balancing time is 300000 ms and there are 50 regions to balance // The balance interval is 6000 ms, much longger than the normal region in transition duration // So the master can balance the region one by one unbalance(master, tableName); AtomicInteger maxCount = new AtomicInteger(0); AtomicBoolean stop = new AtomicBoolean(false); Thread checker = startBalancerChecker(master, maxCount, stop); master.balance(); stop.set(true); checker.interrupt(); checker.join(); assertTrue("max regions in transition: " + maxCount.get(), maxCount.get() == 1); TEST_UTIL.deleteTable(tableName); }
@Test public void testThrottlingByMaxRitPercent() throws Exception { // Set max balancing time to 500 ms and max percent of regions in transition to 0.05 TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_BALANCER_MAX_BALANCING, 500); TEST_UTIL.getConfiguration().setDouble(HConstants.HBASE_MASTER_BALANCER_MAX_RIT_PERCENT, 0.05); TEST_UTIL.startMiniCluster(2); TableName tableName = createTable("testThrottlingByMaxRitPercent"); final HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); unbalance(master, tableName); AtomicInteger maxCount = new AtomicInteger(0); AtomicBoolean stop = new AtomicBoolean(false); Thread checker = startBalancerChecker(master, maxCount, stop); master.balance(); stop.set(true); checker.interrupt(); checker.join(); // The max number of regions in transition is 100 * 0.05 = 5 assertTrue("max regions in transition: " + maxCount.get(), maxCount.get() == 5); TEST_UTIL.deleteTable(tableName); }
@Before public void before() throws Exception { final int balanceCount = MyMasterObserver.postBalanceCount.get(); LOG.info("before"); if (UTIL.ensureSomeRegionServersAvailable(slaves)) { // Distribute regions UTIL.getMiniHBaseCluster().getMaster().balance(); // Some plans are created. if (MyMasterObserver.postBalanceCount.get() > balanceCount) { // It is necessary to wait the move procedure to start. // Otherwise, the next wait may pass immediately. UTIL.waitFor(3 * 1000, 100, false, () -> UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager().hasRegionsInTransition() ); } // Wait until completing balance UTIL.waitUntilAllRegionsAssigned(TEST_TABLE); } LOG.info("before done"); }
/** * Verify the number of region movement is expected */ private void verifyRegionMovementNum(int expected) throws InterruptedException, IOException { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); HMaster m = cluster.getMaster(); int lastRegionOpenedCount = m.getAssignmentManager().getNumRegionsOpened(); // get the assignments start to execute m.balance(); int retry = 10; long sleep = 3000; int attempt = 0; int currentRegionOpened, regionMovement; do { currentRegionOpened = m.getAssignmentManager().getNumRegionsOpened(); regionMovement= currentRegionOpened - lastRegionOpenedCount; LOG.debug("There are " + regionMovement + "/" + expected + " regions moved after " + attempt + " attempts"); Thread.sleep((++attempt) * sleep); } while (regionMovement != expected && attempt <= retry); // update the lastRegionOpenedCount lastRegionOpenedCount = currentRegionOpened; assertEquals("There are only " + regionMovement + " instead of " + expected + " region movement for " + attempt + " attempts", expected, regionMovement); }
} catch (InterruptedException e) {} UTIL.getHBaseCluster().getMaster().balance(); continue;
UTIL.getHBaseCluster().getMaster().balance(); assertRegionsAreBalanced(); assert(UTIL.getHBaseCluster().getMaster().balance() == true); UTIL.getHBaseCluster().startRegionServer().getRegionServer().getServerName()); waitForAllRegionsAssigned(); assert(UTIL.getHBaseCluster().getMaster().balance() == true); assertRegionsAreBalanced(); UTIL.getHBaseCluster().waitOnRegionServer(2); waitOnCrashProcessing(); UTIL.getHBaseCluster().getMaster().balance(); assertRegionsAreBalanced(); waitOnCrashProcessing(); waitForAllRegionsAssigned(); assert(UTIL.getHBaseCluster().getMaster().balance() == true); assertRegionsAreBalanced(); for (int i = 0; i < 6; i++){ assert(UTIL.getHBaseCluster().getMaster().balance() == true); assertRegionsAreBalanced(); regionLocator.close();
cluster.getMaster().balance(); regions = cluster.getMaster().getRegions(); int mNewActualCount = regions.size();
@Override protected void chore() { master.balance(); } };
@Override protected void chore() { try { master.balance(); } catch (IOException e) { LOG.error("Failed to balance.", e); } } }
@Override public BalanceResponse balance(RpcController controller, BalanceRequest request) throws ServiceException { try { return BalanceResponse.newBuilder().setBalancerRan(master.balance()).build(); } catch (IOException ex) { throw new ServiceException(ex); } }
@Test public void testThrottlingByBalanceInterval() throws Exception { // Use default config and start a cluster of two regionservers. TEST_UTIL.startMiniCluster(2); TableName tableName = createTable("testNoThrottling"); final HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); // Default max balancing time is 300000 ms and there are 50 regions to balance // The balance interval is 6000 ms, much longger than the normal region in transition duration // So the master can balance the region one by one unbalance(master, tableName); AtomicInteger maxCount = new AtomicInteger(0); AtomicBoolean stop = new AtomicBoolean(false); Thread checker = startBalancerChecker(master, maxCount, stop); master.balance(); stop.set(true); checker.interrupt(); checker.join(); assertTrue("max regions in transition: " + maxCount.get(), maxCount.get() == 1); TEST_UTIL.deleteTable(tableName); }
@Test public void testThrottlingByMaxRitPercent() throws Exception { // Set max balancing time to 500 ms and max percent of regions in transition to 0.05 TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_BALANCER_MAX_BALANCING, 500); TEST_UTIL.getConfiguration().setDouble(HConstants.HBASE_MASTER_BALANCER_MAX_RIT_PERCENT, 0.05); TEST_UTIL.startMiniCluster(2); TableName tableName = createTable("testThrottlingByMaxRitPercent"); final HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); unbalance(master, tableName); AtomicInteger maxCount = new AtomicInteger(0); AtomicBoolean stop = new AtomicBoolean(false); Thread checker = startBalancerChecker(master, maxCount, stop); master.balance(); stop.set(true); checker.interrupt(); checker.join(); // The max number of regions in transition is 100 * 0.05 = 5 assertTrue("max regions in transition: " + maxCount.get(), maxCount.get() == 5); TEST_UTIL.deleteTable(tableName); }
@Before public void before() throws Exception { final int balanceCount = MyMasterObserver.postBalanceCount.get(); LOG.info("before"); if (UTIL.ensureSomeRegionServersAvailable(slaves)) { // Distribute regions UTIL.getMiniHBaseCluster().getMaster().balance(); // Some plans are created. if (MyMasterObserver.postBalanceCount.get() > balanceCount) { // It is necessary to wait the move procedure to start. // Otherwise, the next wait may pass immediately. UTIL.waitFor(3 * 1000, 100, false, () -> UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager().hasRegionsInTransition() ); } // Wait until completing balance UTIL.waitUntilAllRegionsAssigned(TEST_TABLE); } LOG.info("before done"); }
/** * Verify the number of region movement is expected */ private void verifyRegionMovementNum(int expected) throws InterruptedException, IOException { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); HMaster m = cluster.getMaster(); int lastRegionOpenedCount = m.getAssignmentManager().getNumRegionsOpened(); // get the assignments start to execute m.balance(); int retry = 10; long sleep = 3000; int attempt = 0; int currentRegionOpened, regionMovement; do { currentRegionOpened = m.getAssignmentManager().getNumRegionsOpened(); regionMovement= currentRegionOpened - lastRegionOpenedCount; LOG.debug("There are " + regionMovement + "/" + expected + " regions moved after " + attempt + " attempts"); Thread.sleep((++attempt) * sleep); } while (regionMovement != expected && attempt <= retry); // update the lastRegionOpenedCount lastRegionOpenedCount = currentRegionOpened; assertEquals("There are only " + regionMovement + " instead of " + expected + " region movement for " + attempt + " attempts", expected, regionMovement); }
UTIL.getHBaseCluster().getMaster().balance(); assertRegionsAreBalanced(); assert(UTIL.getHBaseCluster().getMaster().balance() == true); UTIL.getHBaseCluster().startRegionServer().getRegionServer().getServerName()); waitForAllRegionsAssigned(); assert(UTIL.getHBaseCluster().getMaster().balance() == true); assertRegionsAreBalanced(); UTIL.getHBaseCluster().waitOnRegionServer(2); waitOnCrashProcessing(); UTIL.getHBaseCluster().getMaster().balance(); assertRegionsAreBalanced(); waitOnCrashProcessing(); waitForAllRegionsAssigned(); assert(UTIL.getHBaseCluster().getMaster().balance() == true); assertRegionsAreBalanced(); for (int i = 0; i < 6; i++){ assert(UTIL.getHBaseCluster().getMaster().balance() == true); assertRegionsAreBalanced(); regionLocator.close();
cluster.getMaster().balance(); regions = cluster.getMaster().getRegions(); int mNewActualCount = regions.size();