Search in sources :

Example 6 with TransitRegionStateProcedure

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

the class TestServerCrashProcedureStuck method test.

@Test
public void test() throws Exception {
    RegionServerThread rsThread = null;
    for (RegionServerThread t : UTIL.getMiniHBaseCluster().getRegionServerThreads()) {
        if (!t.getRegionServer().getRegions(TABLE_NAME).isEmpty()) {
            rsThread = t;
            break;
        }
    }
    HRegionServer rs = rsThread.getRegionServer();
    RegionInfo hri = rs.getRegions(TABLE_NAME).get(0).getRegionInfo();
    HMaster master = UTIL.getMiniHBaseCluster().getMaster();
    ProcedureExecutor<MasterProcedureEnv> executor = master.getMasterProcedureExecutor();
    DummyRegionProcedure proc = new DummyRegionProcedure(executor.getEnvironment(), hri);
    long procId = master.getMasterProcedureExecutor().submitProcedure(proc);
    proc.waitUntilArrive();
    try (AsyncConnection conn = ConnectionFactory.createAsyncConnection(UTIL.getConfiguration()).get()) {
        AsyncAdmin admin = conn.getAdmin();
        CompletableFuture<Void> future = admin.move(hri.getRegionName());
        rs.abort("For testing!");
        UTIL.waitFor(30000, () -> executor.getProcedures().stream().filter(p -> p instanceof TransitRegionStateProcedure).map(p -> (TransitRegionStateProcedure) p).anyMatch(p -> Bytes.equals(hri.getRegionName(), p.getRegion().getRegionName())));
        proc.resume();
        UTIL.waitFor(30000, () -> executor.isFinished(procId));
        // see whether the move region procedure can finish properly
        future.get(30, TimeUnit.SECONDS);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread) AsyncAdmin(org.apache.hadoop.hbase.client.AsyncAdmin) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) Category(org.junit.experimental.categories.Category) ConnectionFactory(org.apache.hadoop.hbase.client.ConnectionFactory) TimeUnit(java.util.concurrent.TimeUnit) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) AsyncConnection(org.apache.hadoop.hbase.client.AsyncConnection) ProcedureExecutor(org.apache.hadoop.hbase.procedure2.ProcedureExecutor) TransitRegionStateProcedure(org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure) MasterTests(org.apache.hadoop.hbase.testclassification.MasterTests) ClassRule(org.junit.ClassRule) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Bytes(org.apache.hadoop.hbase.util.Bytes) AsyncAdmin(org.apache.hadoop.hbase.client.AsyncAdmin) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) TransitRegionStateProcedure(org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure) AsyncConnection(org.apache.hadoop.hbase.client.AsyncConnection) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread) Test(org.junit.Test)

Example 7 with TransitRegionStateProcedure

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

the class TestSplitRegionWhileRSCrash method test.

@Test
public void test() throws Exception {
    MasterProcedureEnv env = UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor().getEnvironment();
    final ProcedureExecutor<MasterProcedureEnv> executor = UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor();
    List<RegionInfo> regionInfos = ADMIN.getRegions(TABLE_NAME);
    // Since a flush request will be sent while initializing SplitTableRegionProcedure
    // Create SplitTableRegionProcedure first before put data
    SplitTableRegionProcedure splitProcedure = new SplitTableRegionProcedure(env, regionInfos.get(0), Bytes.toBytes("row5"));
    // write some rows to the table
    LOG.info("Begin to put data");
    for (int i = 0; i < 10; i++) {
        byte[] row = Bytes.toBytes("row" + i);
        Put put = new Put(row);
        put.addColumn(CF, CF, CF);
        TABLE.put(put);
    }
    executor.submitProcedure(splitProcedure);
    LOG.info("SplitProcedure submitted");
    UTIL.waitFor(30000, () -> executor.getProcedures().stream().filter(p -> p instanceof TransitRegionStateProcedure).map(p -> (TransitRegionStateProcedure) p).anyMatch(p -> TABLE_NAME.equals(p.getTableName())));
    UTIL.getMiniHBaseCluster().killRegionServer(UTIL.getMiniHBaseCluster().getRegionServer(0).getServerName());
    UTIL.getMiniHBaseCluster().startRegionServer();
    UTIL.waitUntilNoRegionsInTransition();
    Scan scan = new Scan();
    ResultScanner results = TABLE.getScanner(scan);
    int count = 0;
    while (results.next() != null) {
        count++;
    }
    Assert.assertEquals("There should be 10 rows!", 10, count);
}
Also used : BeforeClass(org.junit.BeforeClass) LoggerFactory(org.slf4j.LoggerFactory) ProcedureExecutor(org.apache.hadoop.hbase.procedure2.ProcedureExecutor) Closeables(org.apache.hbase.thirdparty.com.google.common.io.Closeables) SplitTableRegionProcedure(org.apache.hadoop.hbase.master.assignment.SplitTableRegionProcedure) ClassRule(org.junit.ClassRule) Bytes(org.apache.hadoop.hbase.util.Bytes) TableName(org.apache.hadoop.hbase.TableName) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) Put(org.apache.hadoop.hbase.client.Put) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) Test(org.junit.Test) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) Category(org.junit.experimental.categories.Category) Scan(org.apache.hadoop.hbase.client.Scan) List(java.util.List) Admin(org.apache.hadoop.hbase.client.Admin) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) TransitRegionStateProcedure(org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure) MasterTests(org.apache.hadoop.hbase.testclassification.MasterTests) Table(org.apache.hadoop.hbase.client.Table) Assert(org.junit.Assert) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) TransitRegionStateProcedure(org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Scan(org.apache.hadoop.hbase.client.Scan) Put(org.apache.hadoop.hbase.client.Put) SplitTableRegionProcedure(org.apache.hadoop.hbase.master.assignment.SplitTableRegionProcedure) Test(org.junit.Test)

Example 8 with TransitRegionStateProcedure

use of org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure 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 9 with TransitRegionStateProcedure

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

the class TestServerRemoteProcedure method testRegionOpenProcedureIsNotHandledByDispatcher.

@Test
public void testRegionOpenProcedureIsNotHandledByDispatcher() throws Exception {
    TableName tableName = TableName.valueOf("testRegionOpenProcedureIsNotHandledByDisPatcher");
    RegionInfo hri = RegionInfoBuilder.newBuilder(tableName).setStartKey(Bytes.toBytes(1)).setEndKey(Bytes.toBytes(2)).setSplit(false).setRegionId(0).build();
    MasterProcedureEnv env = master.getMasterProcedureExecutor().getEnvironment();
    env.getAssignmentManager().getRegionStates().getOrCreateRegionStateNode(hri);
    TransitRegionStateProcedure proc = TransitRegionStateProcedure.assign(env, hri, null);
    ServerName worker = master.getServerManager().getOnlineServersList().get(0);
    OpenRegionProcedure openRegionProcedure = new OpenRegionProcedure(proc, hri, worker);
    Future<byte[]> future = submitProcedure(openRegionProcedure);
    Thread.sleep(2000);
    rsDispatcher.removeNode(worker);
    try {
        future.get(2000, TimeUnit.MILLISECONDS);
        fail();
    } catch (TimeoutException e) {
        LOG.info("timeout is expected");
    }
    Assert.assertFalse(openRegionProcedure.isFinished());
}
Also used : TableName(org.apache.hadoop.hbase.TableName) TransitRegionStateProcedure(org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure) ServerName(org.apache.hadoop.hbase.ServerName) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) OpenRegionProcedure(org.apache.hadoop.hbase.master.assignment.OpenRegionProcedure) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 10 with TransitRegionStateProcedure

use of org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure 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)

Aggregations

TransitRegionStateProcedure (org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure)13 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)12 Test (org.junit.Test)8 TableName (org.apache.hadoop.hbase.TableName)7 RegionStateNode (org.apache.hadoop.hbase.master.assignment.RegionStateNode)6 ProcedureExecutor (org.apache.hadoop.hbase.procedure2.ProcedureExecutor)6 Bytes (org.apache.hadoop.hbase.util.Bytes)6 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)5 AssignmentManager (org.apache.hadoop.hbase.master.assignment.AssignmentManager)5 List (java.util.List)4 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)4 ServerName (org.apache.hadoop.hbase.ServerName)4 Put (org.apache.hadoop.hbase.client.Put)4 MasterProcedureEnv (org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv)4 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)4 IOException (java.io.IOException)3 TimeUnit (java.util.concurrent.TimeUnit)3 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)3 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)3 Admin (org.apache.hadoop.hbase.client.Admin)3