Search in sources :

Example 6 with BalanceResponse

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();
    }
}
Also used : ServerManager(org.apache.hadoop.hbase.master.ServerManager) LoadBalancer(org.apache.hadoop.hbase.master.LoadBalancer) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) TableName(org.apache.hadoop.hbase.TableName) RegionState(org.apache.hadoop.hbase.master.RegionState) BalanceResponse(org.apache.hadoop.hbase.client.BalanceResponse) RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) Map(java.util.Map) ImmutableMap(org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 7 with BalanceResponse

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());
}
Also used : TableName(org.apache.hadoop.hbase.TableName) BalanceResponse(org.apache.hadoop.hbase.client.BalanceResponse) ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Example 8 with BalanceResponse

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);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) BalanceResponse(org.apache.hadoop.hbase.client.BalanceResponse) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Aggregations

BalanceResponse (org.apache.hadoop.hbase.client.BalanceResponse)8 TableName (org.apache.hadoop.hbase.TableName)5 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ServerName (org.apache.hadoop.hbase.ServerName)3 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)2 BalanceRequest (org.apache.hadoop.hbase.client.BalanceRequest)2 BalanceRSGroupResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.RSGroupAdminProtos.BalanceRSGroupResponse)2 InterruptedIOException (java.io.InterruptedIOException)1 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)1 Admin (org.apache.hadoop.hbase.client.Admin)1 Connection (org.apache.hadoop.hbase.client.Connection)1 LoadBalancer (org.apache.hadoop.hbase.master.LoadBalancer)1 RegionPlan (org.apache.hadoop.hbase.master.RegionPlan)1