Search in sources :

Example 6 with RegionStateNode

use of org.apache.hadoop.hbase.master.assignment.RegionStateNode in project hbase by apache.

the class TestReopenTableRegionsProcedureInfiniteLoop method testInfiniteLoop.

@Test
public void testInfiniteLoop() throws IOException {
    HMaster master = UTIL.getMiniHBaseCluster().getMaster();
    AssignmentManager am = master.getAssignmentManager();
    ProcedureExecutor<MasterProcedureEnv> exec = master.getMasterProcedureExecutor();
    RegionInfo regionInfo = UTIL.getAdmin().getRegions(TABLE_NAME).get(0);
    RegionStateNode regionNode = am.getRegionStates().getRegionStateNode(regionInfo);
    long procId;
    ReopenTableRegionsProcedure proc = new ReopenTableRegionsProcedure(TABLE_NAME);
    regionNode.lock();
    try {
        procId = exec.submitProcedure(proc);
        UTIL.waitFor(30000, () -> proc.hasLock());
        TransitRegionStateProcedure trsp = TransitRegionStateProcedure.reopen(exec.getEnvironment(), regionInfo);
        regionNode.setProcedure(trsp);
        exec.submitProcedure(trsp);
    } finally {
        regionNode.unlock();
    }
    UTIL.waitFor(60000, () -> exec.isFinished(procId));
}
Also used : TransitRegionStateProcedure(org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure) HMaster(org.apache.hadoop.hbase.master.HMaster) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) RegionStateNode(org.apache.hadoop.hbase.master.assignment.RegionStateNode) Test(org.junit.Test)

Example 7 with RegionStateNode

use of org.apache.hadoop.hbase.master.assignment.RegionStateNode in project hbase by apache.

the class TestFavoredStochasticLoadBalancer method testAllFavoredNodesDeadMasterRestarted.

@Ignore
@Test
public void testAllFavoredNodesDeadMasterRestarted() throws Exception {
    TableName tableName = TableName.valueOf("testAllFavoredNodesDeadMasterRestarted");
    TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(ColumnFamilyDescriptorBuilder.of(HConstants.CATALOG_FAMILY)).build();
    admin.createTable(tableDescriptor, Bytes.toBytes("aaa"), Bytes.toBytes("zzz"), REGION_NUM);
    TEST_UTIL.waitTableAvailable(tableName);
    final RegionInfo region = admin.getRegions(tableName).get(0);
    LOG.info("Region that's supposed to be in transition: " + region);
    FavoredNodesManager fnm = master.getFavoredNodesManager();
    List<ServerName> currentFN = fnm.getFavoredNodes(region);
    assertNotNull(currentFN);
    // Lets kill all the RS that are favored nodes for this region.
    stopServersAndWaitUntilProcessed(currentFN);
    final RegionStates regionStatesBeforeMaster = master.getAssignmentManager().getRegionStates();
    TEST_UTIL.waitFor(10000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return regionStatesBeforeMaster.getRegionState(region).isFailedOpen();
        }
    });
    assertTrue("Region: " + region + " should be RIT", regionStatesBeforeMaster.getRegionState(region).isFailedOpen());
    List<RegionInfo> rit = Lists.newArrayList();
    for (RegionStateNode regionState : regionStatesBeforeMaster.getRegionsInTransition()) {
        RegionInfo regionInfo = regionState.getRegionInfo();
        LOG.debug("Region in transition after stopping FN's: " + regionInfo);
        rit.add(regionInfo);
        assertTrue("Region: " + regionInfo + " should be RIT", regionStatesBeforeMaster.getRegionState(regionInfo).isFailedOpen());
        assertEquals("Region: " + regionInfo + " does not belong to table: " + tableName, tableName, regionInfo.getTable());
    }
    Configuration conf = cluster.getConf();
    conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, SLAVES - FavoredNodeAssignmentHelper.FAVORED_NODES_NUM);
    cluster.stopMaster(master.getServerName());
    cluster.waitForMasterToStop(master.getServerName(), 60000);
    cluster.startMaster();
    cluster.waitForActiveAndReadyMaster();
    master = cluster.getMaster();
    fnm = master.getFavoredNodesManager();
    RegionStates regionStates = master.getAssignmentManager().getRegionStates();
    assertTrue("Region: " + region + " should be RIT", regionStates.getRegionState(region).isFailedOpen());
    for (RegionInfo regionInfo : rit) {
        assertTrue("Region: " + regionInfo + " should be RIT", regionStates.getRegionState(regionInfo).isFailedOpen());
    }
    // Regenerate FN and assign, everything else should be fine
    List<ServerName> serversForNewFN = Lists.newArrayList();
    for (ServerName sn : admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet()) {
        serversForNewFN.add(ServerName.valueOf(sn.getHostname(), sn.getPort(), NON_STARTCODE));
    }
    FavoredNodeAssignmentHelper helper = new FavoredNodeAssignmentHelper(serversForNewFN, conf);
    helper.initialize();
    for (RegionInfo regionInfo : rit) {
        List<ServerName> newFavoredNodes = helper.generateFavoredNodes(regionInfo);
        assertNotNull(newFavoredNodes);
        assertEquals(FavoredNodeAssignmentHelper.FAVORED_NODES_NUM, newFavoredNodes.size());
        LOG.info("Region: " + regionInfo.getEncodedName() + " FN: " + newFavoredNodes);
        Map<RegionInfo, List<ServerName>> regionFNMap = Maps.newHashMap();
        regionFNMap.put(regionInfo, newFavoredNodes);
        fnm.updateFavoredNodes(regionFNMap);
        LOG.info("Assigning region: " + regionInfo.getEncodedName());
        admin.assign(regionInfo.getEncodedNameAsBytes());
    }
    TEST_UTIL.waitUntilNoRegionsInTransition(60000);
    assertEquals("Not all regions are online", REGION_NUM, admin.getRegions(tableName).size());
    admin.balancerSwitch(true, true);
    assertTrue("Balancer did not run", admin.balance());
    TEST_UTIL.waitUntilNoRegionsInTransition(60000);
    checkFavoredNodeAssignments(tableName, fnm, regionStates);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) FavoredNodesManager(org.apache.hadoop.hbase.favored.FavoredNodesManager) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) IOException(java.io.IOException) RegionStateNode(org.apache.hadoop.hbase.master.assignment.RegionStateNode) TableName(org.apache.hadoop.hbase.TableName) RegionStates(org.apache.hadoop.hbase.master.assignment.RegionStates) FavoredNodeAssignmentHelper(org.apache.hadoop.hbase.favored.FavoredNodeAssignmentHelper) ServerName(org.apache.hadoop.hbase.ServerName) List(java.util.List) Waiter(org.apache.hadoop.hbase.Waiter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with RegionStateNode

use of org.apache.hadoop.hbase.master.assignment.RegionStateNode in project hbase by apache.

the class TestRSGroupsAdmin2 method testFailedMoveServersTablesAndRepair.

@Test
public void testFailedMoveServersTablesAndRepair() throws Exception {
    // This UT calls moveTablesAndServers() twice to test the idempotency of it.
    // The first time, movement fails because a region is made in SPLITTING state
    // which will not be moved.
    // The second time, the region state is OPEN and check if all
    // regions on target group servers after the call.
    final RSGroupInfo newGroup = addGroup(getGroupName(name.getMethodName()), 1);
    // create table
    final byte[] familyNameBytes = Bytes.toBytes("f");
    TableName table1 = TableName.valueOf(tableName.getNameAsString() + "_1");
    TableName table2 = TableName.valueOf(tableName.getNameAsString() + "_2");
    TEST_UTIL.createMultiRegionTable(table1, familyNameBytes, new Random().nextInt(12) + 4);
    TEST_UTIL.createMultiRegionTable(table2, familyNameBytes, new Random().nextInt(12) + 4);
    // randomly set a region state to SPLITTING to make move abort
    Pair<ServerName, RegionStateNode> gotPair = randomlySetRegionState(newGroup, RegionState.State.SPLITTING, table1, table2);
    RegionStateNode rsn = gotPair.getSecond();
    ServerName srcServer = rsn.getRegionLocation();
    // move server and table to newGroup and check regions
    try {
        ADMIN.moveServersToRSGroup(Sets.newHashSet(srcServer.getAddress()), newGroup.getName());
        ADMIN.setRSGroup(Sets.newHashSet(table2), newGroup.getName());
        fail("should get IOException when retry exhausted but there still exists failed moved " + "regions");
    } catch (Exception e) {
        assertTrue(e.getMessage().contains(gotPair.getSecond().getRegionInfo().getRegionNameAsString()));
    }
    for (RegionInfo regionInfo : MASTER.getAssignmentManager().getAssignedRegions()) {
        if (regionInfo.getTable().equals(table1) && regionInfo.equals(rsn.getRegionInfo())) {
            assertEquals(MASTER.getAssignmentManager().getRegionStates().getRegionServerOfRegion(regionInfo), srcServer);
        }
    }
    // retry moveServersAndTables to newGroup and check if all regions on srcServer belongs to
    // table2
    rsn.setState(RegionState.State.OPEN);
    ADMIN.moveServersToRSGroup(Sets.newHashSet(srcServer.getAddress()), newGroup.getName());
    ADMIN.setRSGroup(Sets.newHashSet(table2), newGroup.getName());
    for (RegionInfo regionsInfo : MASTER.getAssignmentManager().getRegionsOnServer(srcServer)) {
        assertEquals(regionsInfo.getTable(), table2);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Random(java.util.Random) ServerName(org.apache.hadoop.hbase.ServerName) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) IOException(java.io.IOException) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException) RegionStateNode(org.apache.hadoop.hbase.master.assignment.RegionStateNode) Test(org.junit.Test)

Example 9 with RegionStateNode

use of org.apache.hadoop.hbase.master.assignment.RegionStateNode in project hbase by apache.

the class RSGroupInfoManagerImpl method rsGroupGetRegionsInTransition.

private Map<String, RegionState> rsGroupGetRegionsInTransition(String groupName) throws IOException {
    Map<String, RegionState> rit = Maps.newTreeMap();
    Set<TableName> tablesInGroupCache = new HashSet<>();
    for (RegionStateNode regionNode : masterServices.getAssignmentManager().getRegionsInTransition()) {
        TableName tn = regionNode.getTable();
        if (isTableInGroup(tn, groupName, tablesInGroupCache)) {
            rit.put(regionNode.getRegionInfo().getEncodedName(), regionNode.toRegionState());
        }
    }
    return rit;
}
Also used : TableName(org.apache.hadoop.hbase.TableName) RegionState(org.apache.hadoop.hbase.master.RegionState) HashSet(java.util.HashSet) RegionStateNode(org.apache.hadoop.hbase.master.assignment.RegionStateNode)

Example 10 with RegionStateNode

use of org.apache.hadoop.hbase.master.assignment.RegionStateNode in project hbase by apache.

the class AbstractStateMachineTableProcedure method checkOnline.

/**
 * Check region is online.
 */
protected static void checkOnline(MasterProcedureEnv env, RegionInfo ri) throws DoNotRetryRegionException {
    RegionStateNode regionNode = env.getAssignmentManager().getRegionStates().getRegionStateNode(ri);
    if (regionNode == null) {
        throw new UnknownRegionException("No RegionState found for " + ri.getEncodedName());
    }
    regionNode.checkOnline();
}
Also used : UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) RegionStateNode(org.apache.hadoop.hbase.master.assignment.RegionStateNode)

Aggregations

RegionStateNode (org.apache.hadoop.hbase.master.assignment.RegionStateNode)18 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)11 Test (org.junit.Test)9 IOException (java.io.IOException)7 ServerName (org.apache.hadoop.hbase.ServerName)7 TableName (org.apache.hadoop.hbase.TableName)6 AssignmentManager (org.apache.hadoop.hbase.master.assignment.AssignmentManager)5 TransitRegionStateProcedure (org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure)5 List (java.util.List)4 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)3 Waiter (org.apache.hadoop.hbase.Waiter)3 ConstraintException (org.apache.hadoop.hbase.constraint.ConstraintException)3 InterruptedIOException (java.io.InterruptedIOException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Random (java.util.Random)2 UnknownRegionException (org.apache.hadoop.hbase.UnknownRegionException)2 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)2 FavoredNodeAssignmentHelper (org.apache.hadoop.hbase.favored.FavoredNodeAssignmentHelper)2 FavoredNodesManager (org.apache.hadoop.hbase.favored.FavoredNodesManager)2