Search in sources :

Example 36 with RegionPlan

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

the class TestReportRegionStateTransitionFromDeadServer method test.

@Test
public void test() throws HBaseIOException, InterruptedException, ExecutionException {
    RegionInfo region = UTIL.getMiniHBaseCluster().getRegions(NAME).get(0).getRegionInfo();
    AssignmentManager am = UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager();
    RegionStateNode rsn = am.getRegionStates().getRegionStateNode(region);
    // move from rs0 to rs1, and then kill rs0. Later add rs1 to exclude servers, and at last verify
    // that the region should not be on rs1 and rs2 both.
    HRegionServer rs0 = UTIL.getMiniHBaseCluster().getRegionServer(rsn.getRegionLocation());
    HRegionServer rs1 = UTIL.getOtherRegionServer(rs0);
    HRegionServer rs2 = UTIL.getMiniHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer()).filter(rs -> rs != rs0 && rs != rs1).findAny().get();
    RESUME_REPORT = new CountDownLatch(1);
    ARRIVE_REPORT = new CountDownLatch(1);
    Future<?> future = am.moveAsync(new RegionPlan(region, rs0.getServerName(), rs1.getServerName()));
    ARRIVE_REPORT.await();
    RESUME_GET_REGIONS = new CountDownLatch(1);
    ARRIVE_GET_REGIONS = new CountDownLatch(1);
    rs0.abort("For testing!");
    ARRIVE_GET_REGIONS.await();
    RESUME_REPORT.countDown();
    try {
        future.get(15, TimeUnit.SECONDS);
    } catch (TimeoutException e) {
    // after the fix in HBASE-21508 we will get this exception as the TRSP can not be finished any
    // more before SCP interrupts it. It's OK.
    }
    EXCLUDE_SERVERS.add(rs1.getServerName());
    RESUME_GET_REGIONS.countDown();
    // wait until there are no running procedures, no SCP and no TRSP
    UTIL.waitFor(30000, () -> UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor().getActiveProcIds().isEmpty());
    boolean onRS1 = !rs1.getRegions(NAME).isEmpty();
    boolean onRS2 = !rs2.getRegions(NAME).isEmpty();
    assertNotEquals("should either be on rs1 or rs2, but onRS1 is " + onRS1 + " and on RS2 is " + onRS2, onRS1, onRS2);
}
Also used : BeforeClass(org.junit.BeforeClass) TimeoutException(java.util.concurrent.TimeoutException) ReportRegionStateTransitionResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.ReportRegionStateTransitionResponse) ServerManager(org.apache.hadoop.hbase.master.ServerManager) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) HConstants(org.apache.hadoop.hbase.HConstants) PleaseHoldException(org.apache.hadoop.hbase.PleaseHoldException) Configuration(org.apache.hadoop.conf.Configuration) MasterServices(org.apache.hadoop.hbase.master.MasterServices) ClassRule(org.junit.ClassRule) ServerName(org.apache.hadoop.hbase.ServerName) Bytes(org.apache.hadoop.hbase.util.Bytes) TableName(org.apache.hadoop.hbase.TableName) MasterRegion(org.apache.hadoop.hbase.master.region.MasterRegion) AfterClass(org.junit.AfterClass) ProtobufUtil(org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) IOException(java.io.IOException) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) ReportRegionStateTransitionRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.ReportRegionStateTransitionRequest) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) MasterTests(org.apache.hadoop.hbase.testclassification.MasterTests) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) HMaster(org.apache.hadoop.hbase.master.HMaster) RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) CountDownLatch(java.util.concurrent.CountDownLatch) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 37 with RegionPlan

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

the class TestWakeUpUnexpectedProcedure method test.

@Test
public void test() throws Exception {
    RegionInfo region = UTIL.getMiniHBaseCluster().getRegions(NAME).get(0).getRegionInfo();
    AssignmentManager am = UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager();
    RegionStateNode rsn = am.getRegionStates().getRegionStateNode(region);
    ServerName sn = rsn.getRegionLocation();
    RESUME_EXEC_PROC = new CountDownLatch(1);
    ARRIVE_EXEC_PROC = new CountDownLatch(1);
    RESUME_IS_SERVER_ONLINE = new CountDownLatch(1);
    // reopen the region, and halt the executeProcedures method at RS side
    am.moveAsync(new RegionPlan(region, sn, sn));
    ARRIVE_EXEC_PROC.await();
    RESUME_REPORT = new CountDownLatch(1);
    ARRIVE_REPORT = new CountDownLatch(1);
    // kill the region server
    ServerName serverToKill = SERVER_TO_KILL;
    UTIL.getMiniHBaseCluster().stopRegionServer(serverToKill);
    RESUME_EXEC_PROC.countDown();
    // wait until we are going to open the region on a new rs
    ARRIVE_REPORT.await();
    // resume the isServerOnline check, to let the rs procedure
    RESUME_IS_SERVER_ONLINE.countDown();
    // assigned to two regionservers.
    for (int i = 0; i < 15; i++) {
        if (rsn.getState() == RegionState.State.OPEN) {
            break;
        }
        Thread.sleep(1000);
    }
    // resume the old report
    RESUME_REPORT.countDown();
    // wait a bit to let the region to be online, it is not easy to write a condition for this so
    // just sleep a while.
    Thread.sleep(10000);
    // confirm that the region is only on one rs
    int count = 0;
    for (RegionServerThread t : UTIL.getMiniHBaseCluster().getRegionServerThreads()) {
        if (!t.getRegionServer().getRegions(NAME).isEmpty()) {
            LOG.info("{} is on {}", region, t.getRegionServer().getServerName());
            count++;
        }
    }
    assertEquals(1, count);
}
Also used : RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) ServerName(org.apache.hadoop.hbase.ServerName) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 38 with RegionPlan

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

the class RSGroupableBalancerTestBase method reconcile.

protected ArrayListMultimap<String, ServerAndLoad> reconcile(ArrayListMultimap<String, ServerAndLoad> previousLoad, List<RegionPlan> plans) {
    ArrayListMultimap<String, ServerAndLoad> result = ArrayListMultimap.create();
    result.putAll(previousLoad);
    if (plans != null) {
        for (RegionPlan plan : plans) {
            ServerName source = plan.getSource();
            updateLoad(result, source, -1);
            ServerName destination = plan.getDestination();
            updateLoad(result, destination, +1);
        }
    }
    return result;
}
Also used : RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) ServerName(org.apache.hadoop.hbase.ServerName)

Aggregations

RegionPlan (org.apache.hadoop.hbase.master.RegionPlan)38 ServerName (org.apache.hadoop.hbase.ServerName)32 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)24 ArrayList (java.util.ArrayList)21 List (java.util.List)19 HashMap (java.util.HashMap)17 TableName (org.apache.hadoop.hbase.TableName)16 Map (java.util.Map)14 Test (org.junit.Test)14 IOException (java.io.IOException)11 TreeMap (java.util.TreeMap)11 CountDownLatch (java.util.concurrent.CountDownLatch)8 HMaster (org.apache.hadoop.hbase.master.HMaster)7 MasterServices (org.apache.hadoop.hbase.master.MasterServices)7 Configuration (org.apache.hadoop.conf.Configuration)6 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)6 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)6 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)6 MasterRegion (org.apache.hadoop.hbase.master.region.MasterRegion)6 MasterTests (org.apache.hadoop.hbase.testclassification.MasterTests)6