Search in sources :

Example 1 with DisableTableProcedure

use of org.apache.hadoop.hbase.master.procedure.DisableTableProcedure in project hbase by apache.

the class TableNamespaceManager method migrateNamespaceTable.

private void migrateNamespaceTable() throws IOException {
    try (Table nsTable = masterServices.getConnection().getTable(TableName.NAMESPACE_TABLE_NAME);
        ResultScanner scanner = nsTable.getScanner(new Scan().addFamily(TableDescriptorBuilder.NAMESPACE_FAMILY_INFO_BYTES).readAllVersions());
        BufferedMutator mutator = masterServices.getConnection().getBufferedMutator(TableName.META_TABLE_NAME)) {
        for (Result result; ; ) {
            result = scanner.next();
            if (result == null) {
                break;
            }
            Put put = new Put(result.getRow());
            result.getColumnCells(TableDescriptorBuilder.NAMESPACE_FAMILY_INFO_BYTES, TableDescriptorBuilder.NAMESPACE_COL_DESC_BYTES).forEach(c -> put.addColumn(HConstants.NAMESPACE_FAMILY, HConstants.NAMESPACE_COL_DESC_QUALIFIER, c.getTimestamp(), CellUtil.cloneValue(c)));
            mutator.mutate(put);
        }
    }
    // schedule a disable procedure instead of block waiting here, as when disabling a table we will
    // wait until master is initialized, but we are part of the initialization...
    masterServices.getMasterProcedureExecutor().submitProcedure(new DisableTableProcedure(masterServices.getMasterProcedureExecutor().getEnvironment(), TableName.NAMESPACE_TABLE_NAME, false));
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) BufferedMutator(org.apache.hadoop.hbase.client.BufferedMutator) Scan(org.apache.hadoop.hbase.client.Scan) DisableTableProcedure(org.apache.hadoop.hbase.master.procedure.DisableTableProcedure) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result)

Example 2 with DisableTableProcedure

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

Example 3 with DisableTableProcedure

use of org.apache.hadoop.hbase.master.procedure.DisableTableProcedure in project hbase by apache.

the class TestRaceBetweenSCPAndDTP method test.

@Test
public void test() throws Exception {
    RegionInfo region = UTIL.getMiniHBaseCluster().getRegions(NAME).get(0).getRegionInfo();
    AssignmentManager am = UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager();
    ServerName sn = am.getRegionStates().getRegionState(region).getServerName();
    LOG.info("ServerName={}, region={}", sn, region);
    ARRIVE_GET_REGIONS_ON_TABLE = new CountDownLatch(1);
    RESUME_GET_REGIONS_ON_SERVER = new CountDownLatch(1);
    // Assign to local variable because this static gets set to null in above running thread and
    // so NPE.
    CountDownLatch cdl = ARRIVE_GET_REGIONS_ON_TABLE;
    UTIL.getAdmin().disableTableAsync(NAME);
    cdl.await();
    ProcedureExecutor<?> procExec = UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor();
    UTIL.getMiniHBaseCluster().stopRegionServer(sn);
    long pid = Procedure.NO_PROC_ID;
    do {
        Threads.sleep(1);
        pid = getSCPPID(procExec);
    } while (pid != Procedure.NO_PROC_ID);
    final long scppid = pid;
    UTIL.waitFor(60000, () -> procExec.isFinished(scppid));
    RESUME_GET_REGIONS_ON_SERVER.countDown();
    long dtpProcId = procExec.getProcedures().stream().filter(p -> p instanceof DisableTableProcedure).map(p -> (DisableTableProcedure) p).findAny().get().getProcId();
    UTIL.waitFor(60000, () -> procExec.isFinished(dtpProcId));
}
Also used : BeforeClass(org.junit.BeforeClass) LoggerFactory(org.slf4j.LoggerFactory) HConstants(org.apache.hadoop.hbase.HConstants) ProcedureExecutor(org.apache.hadoop.hbase.procedure2.ProcedureExecutor) Configuration(org.apache.hadoop.conf.Configuration) MasterServices(org.apache.hadoop.hbase.master.MasterServices) ClassRule(org.junit.ClassRule) ServerName(org.apache.hadoop.hbase.ServerName) Threads(org.apache.hadoop.hbase.util.Threads) 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) Logger(org.slf4j.Logger) KeeperException(org.apache.zookeeper.KeeperException) 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) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) CountDownLatch(java.util.concurrent.CountDownLatch) DisableTableProcedure(org.apache.hadoop.hbase.master.procedure.DisableTableProcedure) MasterTests(org.apache.hadoop.hbase.testclassification.MasterTests) Optional(java.util.Optional) ServerCrashProcedure(org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) HMaster(org.apache.hadoop.hbase.master.HMaster) ServerName(org.apache.hadoop.hbase.ServerName) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) CountDownLatch(java.util.concurrent.CountDownLatch) DisableTableProcedure(org.apache.hadoop.hbase.master.procedure.DisableTableProcedure) Test(org.junit.Test)

Aggregations

DisableTableProcedure (org.apache.hadoop.hbase.master.procedure.DisableTableProcedure)3 ServerName (org.apache.hadoop.hbase.ServerName)2 TableName (org.apache.hadoop.hbase.TableName)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Optional (java.util.Optional)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Configuration (org.apache.hadoop.conf.Configuration)1 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)1 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)1 HConstants (org.apache.hadoop.hbase.HConstants)1 BufferedMutator (org.apache.hadoop.hbase.client.BufferedMutator)1 Put (org.apache.hadoop.hbase.client.Put)1 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)1 Result (org.apache.hadoop.hbase.client.Result)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 HMaster (org.apache.hadoop.hbase.master.HMaster)1 MasterServices (org.apache.hadoop.hbase.master.MasterServices)1