Search in sources :

Example 1 with BalanceResponse

use of org.apache.hadoop.hbase.client.BalanceResponse in project hbase by apache.

the class MasterRpcServices method balanceRSGroup.

@Override
public BalanceRSGroupResponse balanceRSGroup(RpcController controller, BalanceRSGroupRequest request) throws ServiceException {
    BalanceRequest balanceRequest = ProtobufUtil.toBalanceRequest(request);
    BalanceRSGroupResponse.Builder builder = BalanceRSGroupResponse.newBuilder().setBalanceRan(false);
    LOG.info(server.getClientIdAuditPrefix() + " balance rsgroup, group=" + request.getRSGroupName());
    try {
        if (server.getMasterCoprocessorHost() != null) {
            server.getMasterCoprocessorHost().preBalanceRSGroup(request.getRSGroupName(), balanceRequest);
        }
        BalanceResponse response = server.getRSGroupInfoManager().balanceRSGroup(request.getRSGroupName(), balanceRequest);
        ProtobufUtil.populateBalanceRSGroupResponse(builder, response);
        if (server.getMasterCoprocessorHost() != null) {
            server.getMasterCoprocessorHost().postBalanceRSGroup(request.getRSGroupName(), balanceRequest, response);
        }
    } catch (IOException e) {
        throw new ServiceException(e);
    }
    return builder.build();
}
Also used : BalanceRequest(org.apache.hadoop.hbase.client.BalanceRequest) BalanceRSGroupResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.RSGroupAdminProtos.BalanceRSGroupResponse) BalanceResponse(org.apache.hadoop.hbase.client.BalanceResponse) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException)

Example 2 with BalanceResponse

use of org.apache.hadoop.hbase.client.BalanceResponse in project hbase by apache.

the class HMaster method balanceOrUpdateMetrics.

/**
 *  Trigger a normal balance, see {@link HMaster#balance()} . If the balance is not executed
 *  this time, the metrics related to the balance will be updated.
 *
 *  When balance is running, related metrics will be updated at the same time. But if some
 *  checking logic failed and cause the balancer exit early, we lost the chance to update
 *  balancer metrics. This will lead to user missing the latest balancer info.
 */
public BalanceResponse balanceOrUpdateMetrics() throws IOException {
    synchronized (this.balancer) {
        BalanceResponse response = balance();
        if (!response.isBalancerRan()) {
            Map<TableName, Map<ServerName, List<RegionInfo>>> assignments = this.assignmentManager.getRegionStates().getAssignmentsForBalancer(this.tableStateManager, this.serverManager.getOnlineServersList());
            for (Map<ServerName, List<RegionInfo>> serverMap : assignments.values()) {
                serverMap.keySet().removeAll(this.serverManager.getDrainingServersList());
            }
            this.balancer.updateBalancerLoadInfo(assignments);
        }
        return response;
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) BalanceResponse(org.apache.hadoop.hbase.client.BalanceResponse) ServerName(org.apache.hadoop.hbase.ServerName) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with BalanceResponse

use of org.apache.hadoop.hbase.client.BalanceResponse in project hbase by apache.

the class HMaster method balance.

public BalanceResponse balance(BalanceRequest request) throws IOException {
    checkInitialized();
    BalanceResponse.Builder responseBuilder = BalanceResponse.newBuilder();
    if (loadBalancerTracker == null || !(loadBalancerTracker.isBalancerOn() || request.isDryRun())) {
        return responseBuilder.build();
    }
    if (skipRegionManagementAction("balancer")) {
        return responseBuilder.build();
    }
    synchronized (this.balancer) {
        // Only allow one balance run at at time.
        if (this.assignmentManager.hasRegionsInTransition()) {
            List<RegionStateNode> regionsInTransition = assignmentManager.getRegionsInTransition();
            // if hbase:meta region is in transition, result of assignment cannot be recorded
            // ignore the force flag in that case
            boolean metaInTransition = assignmentManager.isMetaRegionInTransition();
            List<RegionStateNode> toPrint = regionsInTransition;
            int max = 5;
            boolean truncated = false;
            if (regionsInTransition.size() > max) {
                toPrint = regionsInTransition.subList(0, max);
                truncated = true;
            }
            if (!request.isIgnoreRegionsInTransition() || metaInTransition) {
                LOG.info("Not running balancer (ignoreRIT=false" + ", metaRIT=" + metaInTransition + ") because " + regionsInTransition.size() + " region(s) in transition: " + toPrint + (truncated ? "(truncated list)" : ""));
                return responseBuilder.build();
            }
        }
        if (this.serverManager.areDeadServersInProgress()) {
            LOG.info("Not running balancer because processing dead regionserver(s): " + this.serverManager.getDeadServers());
            return responseBuilder.build();
        }
        if (this.cpHost != null) {
            try {
                if (this.cpHost.preBalance(request)) {
                    LOG.debug("Coprocessor bypassing balancer request");
                    return responseBuilder.build();
                }
            } catch (IOException ioe) {
                LOG.error("Error invoking master coprocessor preBalance()", ioe);
                return responseBuilder.build();
            }
        }
        Map<TableName, Map<ServerName, List<RegionInfo>>> assignments = this.assignmentManager.getRegionStates().getAssignmentsForBalancer(tableStateManager, this.serverManager.getOnlineServersList());
        for (Map<ServerName, List<RegionInfo>> serverMap : assignments.values()) {
            serverMap.keySet().removeAll(this.serverManager.getDrainingServersList());
        }
        // Give the balancer the current cluster state.
        this.balancer.updateClusterMetrics(getClusterMetricsWithoutCoprocessor());
        List<RegionPlan> plans = this.balancer.balanceCluster(assignments);
        responseBuilder.setBalancerRan(true).setMovesCalculated(plans == null ? 0 : plans.size());
        if (skipRegionManagementAction("balancer")) {
            // make one last check that the cluster isn't shutting down before proceeding.
            return responseBuilder.build();
        }
        // For dry run we don't actually want to execute the moves, but we do want
        // to execute the coprocessor below
        List<RegionPlan> sucRPs = request.isDryRun() ? Collections.emptyList() : executeRegionPlansWithThrottling(plans);
        if (this.cpHost != null) {
            try {
                this.cpHost.postBalance(request, sucRPs);
            } catch (IOException ioe) {
                // balancing already succeeded so don't change the result
                LOG.error("Error invoking master coprocessor postBalance()", ioe);
            }
        }
        responseBuilder.setMovesExecuted(sucRPs.size());
    }
    // Return true indicating a success.
    return responseBuilder.build();
}
Also used : RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) InterruptedIOException(java.io.InterruptedIOException) RSGroupAdminEndpoint(org.apache.hadoop.hbase.rsgroup.RSGroupAdminEndpoint) RegionStateNode(org.apache.hadoop.hbase.master.assignment.RegionStateNode) TableName(org.apache.hadoop.hbase.TableName) BalanceResponse(org.apache.hadoop.hbase.client.BalanceResponse) ServerName(org.apache.hadoop.hbase.ServerName) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with BalanceResponse

use of org.apache.hadoop.hbase.client.BalanceResponse in project hbase by apache.

the class TestRegionRebalancing method testRebalanceOnRegionServerNumberChange.

/**
 * For HBASE-71. Try a few different configurations of starting and stopping
 * region servers to see if the assignment or regions is pretty balanced.
 * @throws IOException
 * @throws InterruptedException
 */
@Test
public void testRebalanceOnRegionServerNumberChange() throws IOException, InterruptedException {
    try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
        Admin admin = connection.getAdmin()) {
        admin.createTable(this.tableDescriptor, Arrays.copyOfRange(HBaseTestingUtil.KEYS, 1, HBaseTestingUtil.KEYS.length));
        this.regionLocator = connection.getRegionLocator(this.tableDescriptor.getTableName());
        MetaTableAccessor.fullScanMetaAndPrint(admin.getConnection());
        assertEquals("Test table should have right number of regions", HBaseTestingUtil.KEYS.length, this.regionLocator.getStartKeys().length);
        // verify that the region assignments are balanced to start out
        assertRegionsAreBalanced();
        // add a region server - total of 2
        LOG.info("Started second server=" + UTIL.getHBaseCluster().startRegionServer().getRegionServer().getServerName());
        UTIL.getHBaseCluster().getMaster().balance();
        assertRegionsAreBalanced();
        // On a balanced cluster, calling balance() should return true
        BalanceResponse response = UTIL.getHBaseCluster().getMaster().balance();
        assertTrue(response.isBalancerRan());
        assertEquals(0, response.getMovesCalculated());
        assertEquals(0, response.getMovesExecuted());
        // if we add a server, then the balance() call should return true
        // add a region server - total of 3
        LOG.info("Started third server=" + UTIL.getHBaseCluster().startRegionServer().getRegionServer().getServerName());
        waitForAllRegionsAssigned();
        response = UTIL.getHBaseCluster().getMaster().balance();
        assertTrue(response.isBalancerRan());
        assertTrue(response.getMovesCalculated() > 0);
        assertEquals(response.getMovesCalculated(), response.getMovesExecuted());
        assertRegionsAreBalanced();
        // kill a region server - total of 2
        LOG.info("Stopped third server=" + UTIL.getHBaseCluster().stopRegionServer(2, false));
        UTIL.getHBaseCluster().waitOnRegionServer(2);
        waitOnCrashProcessing();
        UTIL.getHBaseCluster().getMaster().balance();
        assertRegionsAreBalanced();
        // start two more region servers - total of 4
        LOG.info("Readding third server=" + UTIL.getHBaseCluster().startRegionServer().getRegionServer().getServerName());
        LOG.info("Added fourth server=" + UTIL.getHBaseCluster().startRegionServer().getRegionServer().getServerName());
        waitOnCrashProcessing();
        waitForAllRegionsAssigned();
        response = UTIL.getHBaseCluster().getMaster().balance();
        assertTrue(response.isBalancerRan());
        assertTrue(response.getMovesCalculated() > 0);
        assertEquals(response.getMovesCalculated(), response.getMovesExecuted());
        assertRegionsAreBalanced();
        for (int i = 0; i < 6; i++) {
            LOG.info("Adding " + (i + 5) + "th region server");
            UTIL.getHBaseCluster().startRegionServer();
        }
        waitForAllRegionsAssigned();
        response = UTIL.getHBaseCluster().getMaster().balance();
        assertTrue(response.isBalancerRan());
        assertTrue(response.getMovesCalculated() > 0);
        assertEquals(response.getMovesCalculated(), response.getMovesExecuted());
        assertRegionsAreBalanced();
        regionLocator.close();
    }
}
Also used : BalanceResponse(org.apache.hadoop.hbase.client.BalanceResponse) Connection(org.apache.hadoop.hbase.client.Connection) Admin(org.apache.hadoop.hbase.client.Admin) Test(org.junit.Test)

Example 5 with BalanceResponse

use of org.apache.hadoop.hbase.client.BalanceResponse in project hbase by apache.

the class RSGroupAdminServiceImpl method balanceRSGroup.

@Override
public void balanceRSGroup(RpcController controller, BalanceRSGroupRequest request, RpcCallback<BalanceRSGroupResponse> done) {
    BalanceRequest balanceRequest = ProtobufUtil.toBalanceRequest(request);
    BalanceRSGroupResponse.Builder builder = BalanceRSGroupResponse.newBuilder().setBalanceRan(false);
    LOG.info(master.getClientIdAuditPrefix() + " balance rsgroup, group=" + request.getRSGroupName());
    try {
        if (master.getMasterCoprocessorHost() != null) {
            master.getMasterCoprocessorHost().preBalanceRSGroup(request.getRSGroupName(), balanceRequest);
        }
        BalanceResponse response = rsGroupInfoManager.balanceRSGroup(request.getRSGroupName(), balanceRequest);
        ProtobufUtil.populateBalanceRSGroupResponse(builder, response);
        if (master.getMasterCoprocessorHost() != null) {
            master.getMasterCoprocessorHost().postBalanceRSGroup(request.getRSGroupName(), balanceRequest, response);
        }
    } catch (IOException e) {
        CoprocessorRpcUtils.setControllerException(controller, e);
    }
    done.run(builder.build());
}
Also used : BalanceRequest(org.apache.hadoop.hbase.client.BalanceRequest) BalanceRSGroupResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.RSGroupAdminProtos.BalanceRSGroupResponse) BalanceResponse(org.apache.hadoop.hbase.client.BalanceResponse) IOException(java.io.IOException)

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