Search in sources :

Example 1 with MergeTableRegionsProcedure

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

the class TestMergeTableRegionsWhileRSCrash method test.

@Test
public void test() throws Exception {
    // write some rows to the table
    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);
    }
    MasterProcedureEnv env = UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor().getEnvironment();
    final ProcedureExecutor<MasterProcedureEnv> executor = UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor();
    List<RegionInfo> regionInfos = admin.getRegions(TABLE_NAME);
    MergeTableRegionsProcedure mergeTableRegionsProcedure = new MergeTableRegionsProcedure(env, new RegionInfo[] { regionInfos.get(0), regionInfos.get(1) }, false);
    executor.submitProcedure(mergeTableRegionsProcedure);
    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;
    Result result = null;
    while ((result = results.next()) != null) {
        count++;
    }
    Assert.assertEquals("There should be 10 rows!", 10, count);
}
Also used : BeforeClass(org.junit.BeforeClass) Result(org.apache.hadoop.hbase.client.Result) LoggerFactory(org.slf4j.LoggerFactory) ProcedureExecutor(org.apache.hadoop.hbase.procedure2.ProcedureExecutor) MergeTableRegionsProcedure(org.apache.hadoop.hbase.master.assignment.MergeTableRegionsProcedure) 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) CountDownLatch(java.util.concurrent.CountDownLatch) 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) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result) MergeTableRegionsProcedure(org.apache.hadoop.hbase.master.assignment.MergeTableRegionsProcedure) TransitRegionStateProcedure(org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure) Scan(org.apache.hadoop.hbase.client.Scan) Test(org.junit.Test)

Example 2 with MergeTableRegionsProcedure

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

the class HMaster method mergeRegions.

@Override
public long mergeRegions(final RegionInfo[] regionsToMerge, final boolean forcible, final long ng, final long nonce) throws IOException {
    checkInitialized();
    if (!isSplitOrMergeEnabled(MasterSwitchType.MERGE)) {
        String regionsStr = Arrays.deepToString(regionsToMerge);
        LOG.warn("Merge switch is off! skip merge of " + regionsStr);
        throw new DoNotRetryIOException("Merge of " + regionsStr + " failed because merge switch is off");
    }
    final String mergeRegionsStr = Arrays.stream(regionsToMerge).map(RegionInfo::getEncodedName).collect(Collectors.joining(", "));
    return MasterProcedureUtil.submitProcedure(new NonceProcedureRunnable(this, ng, nonce) {

        @Override
        protected void run() throws IOException {
            getMaster().getMasterCoprocessorHost().preMergeRegions(regionsToMerge);
            String aid = getClientIdAuditPrefix();
            LOG.info("{} merge regions {}", aid, mergeRegionsStr);
            submitProcedure(new MergeTableRegionsProcedure(procedureExecutor.getEnvironment(), regionsToMerge, forcible));
            getMaster().getMasterCoprocessorHost().postMergeRegions(regionsToMerge);
        }

        @Override
        protected String getDescription() {
            return "MergeTableProcedure";
        }
    });
}
Also used : MergeTableRegionsProcedure(org.apache.hadoop.hbase.master.assignment.MergeTableRegionsProcedure) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) NonceProcedureRunnable(org.apache.hadoop.hbase.master.procedure.MasterProcedureUtil.NonceProcedureRunnable) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) InterruptedIOException(java.io.InterruptedIOException)

Aggregations

MergeTableRegionsProcedure (org.apache.hadoop.hbase.master.assignment.MergeTableRegionsProcedure)2 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)1 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)1 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)1 TableName (org.apache.hadoop.hbase.TableName)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 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 TransitRegionStateProcedure (org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure)1 MasterProcedureEnv (org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv)1 NonceProcedureRunnable (org.apache.hadoop.hbase.master.procedure.MasterProcedureUtil.NonceProcedureRunnable)1