Search in sources :

Example 21 with AssignmentManager

use of org.apache.hadoop.hbase.master.AssignmentManager in project hbase by apache.

the class TestHBaseFsckOneRS method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    TEST_UTIL.getConfiguration().set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, MasterSyncObserver.class.getName());
    conf.setInt("hbase.regionserver.handler.count", 2);
    conf.setInt("hbase.regionserver.metahandler.count", 30);
    conf.setInt("hbase.htable.threads.max", POOL_SIZE);
    conf.setInt("hbase.hconnection.threads.max", 2 * POOL_SIZE);
    conf.setInt("hbase.hbck.close.timeout", 2 * REGION_ONLINE_TIMEOUT);
    conf.setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, 8 * REGION_ONLINE_TIMEOUT);
    TEST_UTIL.startMiniCluster(1);
    tableExecutorService = new ThreadPoolExecutor(1, POOL_SIZE, 60, TimeUnit.SECONDS, new SynchronousQueue<>(), Threads.newDaemonThreadFactory("testhbck"));
    hbfsckExecutorService = new ScheduledThreadPoolExecutor(POOL_SIZE);
    AssignmentManager assignmentManager = TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager();
    regionStates = assignmentManager.getRegionStates();
    connection = (ClusterConnection) TEST_UTIL.getConnection();
    admin = connection.getAdmin();
    admin.setBalancerRunning(false, true);
    TEST_UTIL.waitUntilAllRegionsAssigned(TableName.META_TABLE_NAME);
    TEST_UTIL.waitUntilAllRegionsAssigned(TableName.NAMESPACE_TABLE_NAME);
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) SynchronousQueue(java.util.concurrent.SynchronousQueue) AssignmentManager(org.apache.hadoop.hbase.master.AssignmentManager) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) BeforeClass(org.junit.BeforeClass)

Example 22 with AssignmentManager

use of org.apache.hadoop.hbase.master.AssignmentManager in project hbase by apache.

the class RSGroupAdminServer method balanceRSGroup.

@Override
public boolean balanceRSGroup(String groupName) throws IOException {
    ServerManager serverManager = master.getServerManager();
    AssignmentManager assignmentManager = master.getAssignmentManager();
    LoadBalancer balancer = master.getLoadBalancer();
    boolean balancerRan;
    synchronized (balancer) {
        if (master.getMasterCoprocessorHost() != null) {
            master.getMasterCoprocessorHost().preBalanceRSGroup(groupName);
        }
        if (getRSGroupInfo(groupName) == null) {
            throw new ConstraintException("RSGroup does not exist: " + groupName);
        }
        // Only allow one balance run at at time.
        Map<String, RegionState> groupRIT = rsGroupGetRegionsInTransition(groupName);
        if (groupRIT.size() > 0) {
            LOG.debug("Not running balancer because " + groupRIT.size() + " region(s) in transition: " + StringUtils.abbreviate(master.getAssignmentManager().getRegionStates().getRegionsInTransition().toString(), 256));
            return false;
        }
        if (serverManager.areDeadServersInProgress()) {
            LOG.debug("Not running balancer because processing dead regionserver(s): " + serverManager.getDeadServers());
            return false;
        }
        //We balance per group instead of per table
        List<RegionPlan> plans = new ArrayList<>();
        for (Map.Entry<TableName, Map<ServerName, List<HRegionInfo>>> tableMap : getRSGroupAssignmentsByTable(groupName).entrySet()) {
            LOG.info("Creating partial plan for table " + tableMap.getKey() + ": " + tableMap.getValue());
            List<RegionPlan> partialPlans = balancer.balanceCluster(tableMap.getValue());
            LOG.info("Partial plan for table " + tableMap.getKey() + ": " + partialPlans);
            if (partialPlans != null) {
                plans.addAll(partialPlans);
            }
        }
        long startTime = System.currentTimeMillis();
        balancerRan = plans != null;
        if (plans != null && !plans.isEmpty()) {
            LOG.info("RSGroup balance " + groupName + " starting with plan count: " + plans.size());
            for (RegionPlan plan : plans) {
                LOG.info("balance " + plan);
                assignmentManager.balance(plan);
            }
            LOG.info("RSGroup balance " + groupName + " completed after " + (System.currentTimeMillis() - startTime) + " seconds");
        }
        if (master.getMasterCoprocessorHost() != null) {
            master.getMasterCoprocessorHost().postBalanceRSGroup(groupName, balancerRan);
        }
    }
    return balancerRan;
}
Also used : ServerManager(org.apache.hadoop.hbase.master.ServerManager) AssignmentManager(org.apache.hadoop.hbase.master.AssignmentManager) ArrayList(java.util.ArrayList) LoadBalancer(org.apache.hadoop.hbase.master.LoadBalancer) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) RegionState(org.apache.hadoop.hbase.master.RegionState) RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) HashMap(java.util.HashMap) Map(java.util.Map)

Example 23 with AssignmentManager

use of org.apache.hadoop.hbase.master.AssignmentManager in project hbase by apache.

the class TestRSGroupBasedLoadBalancer method getMockedMaster.

private static MasterServices getMockedMaster() throws IOException {
    TableDescriptors tds = Mockito.mock(TableDescriptors.class);
    Mockito.when(tds.get(tables[0])).thenReturn(tableDescs.get(0));
    Mockito.when(tds.get(tables[1])).thenReturn(tableDescs.get(1));
    Mockito.when(tds.get(tables[2])).thenReturn(tableDescs.get(2));
    Mockito.when(tds.get(tables[3])).thenReturn(tableDescs.get(3));
    MasterServices services = Mockito.mock(HMaster.class);
    Mockito.when(services.getTableDescriptors()).thenReturn(tds);
    AssignmentManager am = Mockito.mock(AssignmentManager.class);
    Mockito.when(services.getAssignmentManager()).thenReturn(am);
    return services;
}
Also used : TableDescriptors(org.apache.hadoop.hbase.TableDescriptors) AssignmentManager(org.apache.hadoop.hbase.master.AssignmentManager) MasterServices(org.apache.hadoop.hbase.master.MasterServices)

Example 24 with AssignmentManager

use of org.apache.hadoop.hbase.master.AssignmentManager in project phoenix by apache.

the class PhoenixServerRpcIT method ensureTablesOnDifferentRegionServers.

/**
	 * Verifies that the given tables each have a single region and are on
	 * different region servers. If they are on the same server moves tableName2
	 * to the other region server.
	 */
private void ensureTablesOnDifferentRegionServers(String tableName1, String tableName2) throws Exception {
    byte[] table1 = Bytes.toBytes(tableName1);
    byte[] table2 = Bytes.toBytes(tableName2);
    HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), TEST_PROPERTIES).getAdmin();
    HBaseTestingUtility util = getUtility();
    MiniHBaseCluster cluster = util.getHBaseCluster();
    HMaster master = cluster.getMaster();
    AssignmentManager am = master.getAssignmentManager();
    // verify there is only a single region for data table
    List<HRegionInfo> tableRegions = admin.getTableRegions(table1);
    assertEquals("Expected single region for " + table1, tableRegions.size(), 1);
    HRegionInfo hri1 = tableRegions.get(0);
    // verify there is only a single region for index table
    tableRegions = admin.getTableRegions(table2);
    HRegionInfo hri2 = tableRegions.get(0);
    assertEquals("Expected single region for " + table2, tableRegions.size(), 1);
    ServerName serverName1 = am.getRegionStates().getRegionServerOfRegion(hri1);
    ServerName serverName2 = am.getRegionStates().getRegionServerOfRegion(hri2);
    // if data table and index table are on same region server, move the index table to the other region server
    if (serverName1.equals(serverName2)) {
        HRegionServer server1 = util.getHBaseCluster().getRegionServer(0);
        HRegionServer server2 = util.getHBaseCluster().getRegionServer(1);
        HRegionServer dstServer = null;
        HRegionServer srcServer = null;
        if (server1.getServerName().equals(serverName2)) {
            dstServer = server2;
            srcServer = server1;
        } else {
            dstServer = server1;
            srcServer = server2;
        }
        byte[] encodedRegionNameInBytes = hri2.getEncodedNameAsBytes();
        admin.move(encodedRegionNameInBytes, Bytes.toBytes(dstServer.getServerName().getServerName()));
        while (dstServer.getOnlineRegion(hri2.getRegionName()) == null || dstServer.getRegionsInTransitionInRS().containsKey(encodedRegionNameInBytes) || srcServer.getRegionsInTransitionInRS().containsKey(encodedRegionNameInBytes) || master.getAssignmentManager().getRegionStates().isRegionsInTransition()) {
            // wait for the move to be finished
            Thread.sleep(1);
        }
    }
    hri1 = admin.getTableRegions(table1).get(0);
    serverName1 = am.getRegionStates().getRegionServerOfRegion(hri1);
    hri2 = admin.getTableRegions(table2).get(0);
    serverName2 = am.getRegionStates().getRegionServerOfRegion(hri2);
    // verify index and data tables are on different servers
    assertNotEquals("Tables " + tableName1 + " and " + tableName2 + " should be on different region servers", serverName1, serverName2);
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) ServerName(org.apache.hadoop.hbase.ServerName) HMaster(org.apache.hadoop.hbase.master.HMaster) AssignmentManager(org.apache.hadoop.hbase.master.AssignmentManager) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer)

Aggregations

AssignmentManager (org.apache.hadoop.hbase.master.AssignmentManager)24 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)13 ServerName (org.apache.hadoop.hbase.ServerName)6 TableName (org.apache.hadoop.hbase.TableName)6 RegionStates (org.apache.hadoop.hbase.master.RegionStates)6 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)4 SynchronousQueue (java.util.concurrent.SynchronousQueue)4 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)4 MiniHBaseCluster (org.apache.hadoop.hbase.MiniHBaseCluster)4 RegionState (org.apache.hadoop.hbase.master.RegionState)4 BeforeClass (org.junit.BeforeClass)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HMaster (org.apache.hadoop.hbase.master.HMaster)3 MasterWalManager (org.apache.hadoop.hbase.master.MasterWalManager)3 IOException (java.io.IOException)2 InterruptedIOException (java.io.InterruptedIOException)2 List (java.util.List)2 Map (java.util.Map)2