Search in sources :

Example 16 with RegionStateNode

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

the class TestMasterAbortAndRSGotKilled method test.

@Test
public void test() throws Exception {
    JVMClusterUtil.RegionServerThread rsThread = null;
    for (JVMClusterUtil.RegionServerThread t : UTIL.getMiniHBaseCluster().getRegionServerThreads()) {
        if (!t.getRegionServer().getRegions(TABLE_NAME).isEmpty()) {
            rsThread = t;
            break;
        }
    }
    // find the rs and hri of the table
    HRegionServer rs = rsThread.getRegionServer();
    RegionInfo hri = rs.getRegions(TABLE_NAME).get(0).getRegionInfo();
    TransitRegionStateProcedure moveRegionProcedure = TransitRegionStateProcedure.reopen(UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor().getEnvironment(), hri);
    RegionStateNode regionNode = UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager().getRegionStates().getOrCreateRegionStateNode(hri);
    regionNode.setProcedure(moveRegionProcedure);
    UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor().submitProcedure(moveRegionProcedure);
    countDownLatch.await();
    UTIL.getMiniHBaseCluster().stopMaster(0);
    UTIL.getMiniHBaseCluster().startMaster();
    // wait until master initialized
    UTIL.waitFor(30000, () -> UTIL.getMiniHBaseCluster().getMaster() != null && UTIL.getMiniHBaseCluster().getMaster().isInitialized());
    Assert.assertTrue("Should be 3 RS after master restart", UTIL.getMiniHBaseCluster().getLiveRegionServerThreads().size() == 3);
}
Also used : TransitRegionStateProcedure(org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure) JVMClusterUtil(org.apache.hadoop.hbase.util.JVMClusterUtil) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) RegionStateNode(org.apache.hadoop.hbase.master.assignment.RegionStateNode) Test(org.junit.Test)

Example 17 with RegionStateNode

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

the class TestReopenTableRegionsProcedureBackoff method testRetryBackoff.

@Test
public void testRetryBackoff() throws IOException, InterruptedException {
    AssignmentManager am = UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager();
    ProcedureExecutor<MasterProcedureEnv> procExec = UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor();
    RegionInfo regionInfo = UTIL.getAdmin().getRegions(TABLE_NAME).get(0);
    RegionStateNode regionNode = am.getRegionStates().getRegionStateNode(regionInfo);
    // just a dummy one
    TransitRegionStateProcedure trsp = TransitRegionStateProcedure.unassign(procExec.getEnvironment(), regionInfo);
    long openSeqNum;
    regionNode.lock();
    try {
        openSeqNum = regionNode.getOpenSeqNum();
        // make a fake state to let the procedure wait.
        regionNode.setState(State.OPENING);
        regionNode.setOpenSeqNum(-1L);
        regionNode.setProcedure(trsp);
    } finally {
        regionNode.unlock();
    }
    ReopenTableRegionsProcedure proc = new ReopenTableRegionsProcedure(TABLE_NAME);
    procExec.submitProcedure(proc);
    UTIL.waitFor(10000, () -> proc.getState() == ProcedureState.WAITING_TIMEOUT);
    long oldTimeout = 0;
    int timeoutIncrements = 0;
    for (; ; ) {
        long timeout = proc.getTimeout();
        if (timeout > oldTimeout) {
            LOG.info("Timeout incremented, was {}, now is {}, increments={}", timeout, oldTimeout, timeoutIncrements);
            oldTimeout = timeout;
            timeoutIncrements++;
            if (timeoutIncrements > 3) {
                // If we incremented at least twice, break; the backoff is working.
                break;
            }
        }
        Thread.sleep(1000);
    }
    regionNode.lock();
    try {
        // reset to the correct state
        regionNode.setState(State.OPEN);
        regionNode.setOpenSeqNum(openSeqNum);
        regionNode.unsetProcedure(trsp);
    } finally {
        regionNode.unlock();
    }
    ProcedureSyncWait.waitForProcedureToComplete(procExec, proc, 60000);
    assertTrue(regionNode.getOpenSeqNum() > openSeqNum);
}
Also used : TransitRegionStateProcedure(org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure) 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 18 with RegionStateNode

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

the class TestFavoredStochasticLoadBalancer method testAllFavoredNodesDead.

@Ignore
@Test
public void testAllFavoredNodesDead() throws Exception {
    TableName tableName = TableName.valueOf("testAllFavoredNodesDead");
    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 regionStates = master.getAssignmentManager().getRegionStates();
    TEST_UTIL.waitFor(10000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return regionStates.getRegionState(region).isFailedOpen();
        }
    });
    assertTrue("Region: " + region + " should be RIT", regionStates.getRegionState(region).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 (RegionStateNode regionState : regionStates.getRegionsInTransition()) {
        RegionInfo regionInfo = regionState.getRegionInfo();
        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 : 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)

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