Search in sources :

Example 1 with SplitTableRegionProcedure

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

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

the class TestDirectStoreSplitsMerges method waitForSplitProcComplete.

private void waitForSplitProcComplete(int attempts, int waitTime) throws Exception {
    List<Procedure<?>> procedures = TEST_UTIL.getHBaseCluster().getMaster().getProcedures();
    if (procedures.size() > 0) {
        Procedure splitProc = procedures.stream().filter(p -> p instanceof SplitTableRegionProcedure).findFirst().get();
        int count = 0;
        while ((splitProc.isWaiting() || splitProc.isRunnable()) && count < attempts) {
            synchronized (splitProc) {
                splitProc.wait(waitTime);
            }
            count++;
        }
        assertTrue(splitProc.isSuccess());
    }
}
Also used : SplitTableRegionProcedure(org.apache.hadoop.hbase.master.assignment.SplitTableRegionProcedure) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) SplitTableRegionProcedure(org.apache.hadoop.hbase.master.assignment.SplitTableRegionProcedure)

Example 3 with SplitTableRegionProcedure

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

the class TestSplitOrMergeStatus method testSplitRegionReplicaRitRecovery.

@Test
public void testSplitRegionReplicaRitRecovery() throws Exception {
    int startRowNum = 11;
    int rowCount = 60;
    final TableName tableName = TableName.valueOf(name.getMethodName());
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    TEST_UTIL.getAdmin().createTable(TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)).setRegionReplication(2).build());
    TEST_UTIL.waitUntilAllRegionsAssigned(tableName);
    ServerName serverName = RegionReplicaTestHelper.getRSCarryingReplica(TEST_UTIL, tableName, 1).get();
    List<RegionInfo> regions = TEST_UTIL.getAdmin().getRegions(tableName);
    insertData(tableName, startRowNum, rowCount);
    int splitRowNum = startRowNum + rowCount / 2;
    byte[] splitKey = Bytes.toBytes("" + splitRowNum);
    // Split region of the table
    long procId = procExec.submitProcedure(new SplitTableRegionProcedure(procExec.getEnvironment(), regions.get(0), splitKey));
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId);
    // Disable the table
    long procId1 = procExec.submitProcedure(new DisableTableProcedure(procExec.getEnvironment(), tableName, false));
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId1);
    // Delete Table
    long procId2 = procExec.submitProcedure(new DeleteTableProcedure(procExec.getEnvironment(), tableName));
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId2);
    AssignmentTestingUtil.killRs(TEST_UTIL, serverName);
    Threads.sleepWithoutInterrupt(5000);
    boolean hasRegionsInTransition = TEST_UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager().getRegionStates().hasRegionsInTransition();
    assertEquals(false, hasRegionsInTransition);
}
Also used : MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) DeleteTableProcedure(org.apache.hadoop.hbase.master.procedure.DeleteTableProcedure) DisableTableProcedure(org.apache.hadoop.hbase.master.procedure.DisableTableProcedure) SplitTableRegionProcedure(org.apache.hadoop.hbase.master.assignment.SplitTableRegionProcedure) TableName(org.apache.hadoop.hbase.TableName) ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Aggregations

SplitTableRegionProcedure (org.apache.hadoop.hbase.master.assignment.SplitTableRegionProcedure)3 TableName (org.apache.hadoop.hbase.TableName)2 MasterProcedureEnv (org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv)2 Test (org.junit.Test)2 List (java.util.List)1 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)1 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)1 ServerName (org.apache.hadoop.hbase.ServerName)1 Admin (org.apache.hadoop.hbase.client.Admin)1 Put (org.apache.hadoop.hbase.client.Put)1 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)1 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)1 Scan (org.apache.hadoop.hbase.client.Scan)1 Table (org.apache.hadoop.hbase.client.Table)1 TransitRegionStateProcedure (org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure)1 DeleteTableProcedure (org.apache.hadoop.hbase.master.procedure.DeleteTableProcedure)1 DisableTableProcedure (org.apache.hadoop.hbase.master.procedure.DisableTableProcedure)1 Procedure (org.apache.hadoop.hbase.procedure2.Procedure)1 ProcedureExecutor (org.apache.hadoop.hbase.procedure2.ProcedureExecutor)1 MasterTests (org.apache.hadoop.hbase.testclassification.MasterTests)1