use of org.apache.hadoop.hbase.client.BalanceResponse in project hbase by apache.
the class RSGroupInfoManagerImpl method balanceRSGroup.
@Override
public BalanceResponse balanceRSGroup(String groupName, BalanceRequest request) throws IOException {
ServerManager serverManager = masterServices.getServerManager();
LoadBalancer balancer = masterServices.getLoadBalancer();
getRSGroupInfo(groupName);
BalanceResponse.Builder responseBuilder = BalanceResponse.newBuilder();
synchronized (balancer) {
// If balance not true, don't run balancer.
if (!masterServices.isBalancerOn() && !request.isDryRun()) {
return responseBuilder.build();
}
// Only allow one balance run at at time.
Map<String, RegionState> groupRIT = rsGroupGetRegionsInTransition(groupName);
if (groupRIT.size() > 0 && !request.isIgnoreRegionsInTransition()) {
LOG.debug("Not running balancer because {} region(s) in transition: {}", groupRIT.size(), StringUtils.abbreviate(masterServices.getAssignmentManager().getRegionStates().getRegionsInTransition().toString(), 256));
return responseBuilder.build();
}
if (serverManager.areDeadServersInProgress()) {
LOG.debug("Not running balancer because processing dead regionserver(s): {}", serverManager.getDeadServers());
return responseBuilder.build();
}
// We balance per group instead of per table
Map<TableName, Map<ServerName, List<RegionInfo>>> assignmentsByTable = getRSGroupAssignmentsByTable(masterServices.getTableStateManager(), groupName);
List<RegionPlan> plans = balancer.balanceCluster(assignmentsByTable);
boolean balancerRan = !plans.isEmpty();
responseBuilder.setBalancerRan(balancerRan).setMovesCalculated(plans.size());
if (balancerRan && !request.isDryRun()) {
LOG.info("RSGroup balance {} starting with plan count: {}", groupName, plans.size());
List<RegionPlan> executed = masterServices.executeRegionPlansWithThrottling(plans);
responseBuilder.setMovesExecuted(executed.size());
LOG.info("RSGroup balance " + groupName + " completed");
}
return responseBuilder.build();
}
}
use of org.apache.hadoop.hbase.client.BalanceResponse in project hbase by apache.
the class TestRSGroupsBalance method testGroupDryRunBalance.
@Test
public void testGroupDryRunBalance() throws Exception {
String methodName = name.getMethodName();
LOG.info(methodName);
String newGroupName = getGroupName(methodName);
final TableName tableName = TableName.valueOf(TABLE_PREFIX + "_ns", methodName);
ServerName first = setupBalanceTest(newGroupName, tableName);
// run the balancer in dry run mode. it should return true, but should not actually move any regions
ADMIN.balancerSwitch(true, true);
BalanceResponse response = ADMIN.balanceRSGroup(newGroupName, BalanceRequest.newBuilder().setDryRun(true).build());
assertTrue(response.isBalancerRan());
assertTrue(response.getMovesCalculated() > 0);
assertEquals(0, response.getMovesExecuted());
// validate imbalance still exists.
assertEquals(6, getTableServerRegionMap().get(tableName).get(first).size());
}
use of org.apache.hadoop.hbase.client.BalanceResponse in project hbase by apache.
the class TestMasterDryRunBalancer method testDryRunBalancer.
@Test
public void testDryRunBalancer() throws Exception {
TEST_UTIL.startMiniCluster(2);
int numRegions = 100;
int regionsPerRs = numRegions / 2;
TableName tableName = createTable("testDryRunBalancer", numRegions);
HMaster master = Mockito.spy(TEST_UTIL.getHBaseCluster().getMaster());
// dry run should be possible with balancer disabled
// disabling it will ensure the chore does not mess with our forced unbalance below
master.balanceSwitch(false);
assertFalse(master.isBalancerOn());
HRegionServer biasedServer = unbalance(master, tableName);
BalanceResponse response = master.balance(BalanceRequest.newBuilder().setDryRun(true).build());
assertTrue(response.isBalancerRan());
// we don't know for sure that it will be exactly half the regions
assertTrue(response.getMovesCalculated() >= (regionsPerRs - 1) && response.getMovesCalculated() <= (regionsPerRs + 1));
// but we expect no moves executed due to dry run
assertEquals(0, response.getMovesExecuted());
// sanity check that we truly don't try to execute any plans
Mockito.verify(master, Mockito.never()).executeRegionPlansWithThrottling(Mockito.anyList());
// should still be unbalanced post dry run
assertServerContainsAllRegions(biasedServer.getServerName(), tableName);
TEST_UTIL.deleteTable(tableName);
}
Aggregations