Search in sources :

Example 36 with MasterProcedureEnv

use of org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv 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 37 with MasterProcedureEnv

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

the class HMaster method createProcedureExecutor.

private void createProcedureExecutor() throws IOException {
    MasterProcedureEnv procEnv = new MasterProcedureEnv(this);
    procedureStore = new RegionProcedureStore(this, masterRegion, new MasterProcedureEnv.FsUtilsLeaseRecovery(this));
    procedureStore.registerListener(new ProcedureStoreListener() {

        @Override
        public void abortProcess() {
            abort("The Procedure Store lost the lease", null);
        }
    });
    MasterProcedureScheduler procedureScheduler = procEnv.getProcedureScheduler();
    procedureExecutor = new ProcedureExecutor<>(conf, procEnv, procedureStore, procedureScheduler);
    configurationManager.registerObserver(procEnv);
    int cpus = Runtime.getRuntime().availableProcessors();
    final int numThreads = conf.getInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, Math.max((cpus > 0 ? cpus / 4 : 0), MasterProcedureConstants.DEFAULT_MIN_MASTER_PROCEDURE_THREADS));
    final boolean abortOnCorruption = conf.getBoolean(MasterProcedureConstants.EXECUTOR_ABORT_ON_CORRUPTION, MasterProcedureConstants.DEFAULT_EXECUTOR_ABORT_ON_CORRUPTION);
    procedureStore.start(numThreads);
    // Just initialize it but do not start the workers, we will start the workers later by calling
    // startProcedureExecutor. See the javadoc for finishActiveMasterInitialization for more
    // details.
    procedureExecutor.init(numThreads, abortOnCorruption);
    if (!procEnv.getRemoteDispatcher().start()) {
        throw new HBaseIOException("Failed start of remote dispatcher");
    }
}
Also used : HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) RegionProcedureStore(org.apache.hadoop.hbase.procedure2.store.region.RegionProcedureStore) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) MasterProcedureScheduler(org.apache.hadoop.hbase.master.procedure.MasterProcedureScheduler) ProcedureStoreListener(org.apache.hadoop.hbase.procedure2.store.ProcedureStore.ProcedureStoreListener) RSGroupAdminEndpoint(org.apache.hadoop.hbase.rsgroup.RSGroupAdminEndpoint)

Example 38 with MasterProcedureEnv

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

the class TestSnapshotWhileRSCrashes method test.

@Test
public void test() throws InterruptedException, IOException {
    String snName = "sn";
    MasterLock lock = UTIL.getMiniHBaseCluster().getMaster().getLockManager().createMasterLock(NAME, LockType.EXCLUSIVE, "for testing");
    lock.acquire();
    Thread t = new Thread(() -> {
        try {
            UTIL.getAdmin().snapshot(snName, NAME);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    });
    t.setDaemon(true);
    t.start();
    ProcedureExecutor<MasterProcedureEnv> procExec = UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor();
    UTIL.waitFor(10000, () -> procExec.getProcedures().stream().filter(p -> !p.isFinished()).filter(p -> p instanceof LockProcedure).map(p -> (LockProcedure) p).filter(p -> NAME.equals(p.getTableName())).anyMatch(p -> !p.isLocked()));
    UTIL.getMiniHBaseCluster().stopRegionServer(0);
    lock.release();
    // sure that the regions could online
    try (Table table = UTIL.getConnection().getTable(NAME);
        ResultScanner scanner = table.getScanner(CF)) {
        assertNull(scanner.next());
    }
}
Also used : MasterLock(org.apache.hadoop.hbase.master.locking.LockManager.MasterLock) 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) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) IOException(java.io.IOException) Test(org.junit.Test) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) Category(org.junit.experimental.categories.Category) LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) LockType(org.apache.hadoop.hbase.procedure2.LockType) UncheckedIOException(java.io.UncheckedIOException) Assert.assertNull(org.junit.Assert.assertNull) ProcedureExecutor(org.apache.hadoop.hbase.procedure2.ProcedureExecutor) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) MasterTests(org.apache.hadoop.hbase.testclassification.MasterTests) Table(org.apache.hadoop.hbase.client.Table) ClassRule(org.junit.ClassRule) Bytes(org.apache.hadoop.hbase.util.Bytes) LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) UncheckedIOException(java.io.UncheckedIOException) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) MasterLock(org.apache.hadoop.hbase.master.locking.LockManager.MasterLock) Test(org.junit.Test)

Example 39 with MasterProcedureEnv

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

the class TestTransitPeerSyncReplicationStateProcedureRetry method testRecoveryAndDoubleExecution.

@Test
public void testRecoveryAndDoubleExecution() throws Exception {
    UTIL2.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID, SyncReplicationState.STANDBY);
    UTIL1.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID, SyncReplicationState.ACTIVE);
    UTIL1.getAdmin().disableReplicationPeer(PEER_ID);
    write(UTIL1, 0, 100);
    Thread.sleep(2000);
    // peer is disabled so no data have been replicated
    verifyNotReplicatedThroughRegion(UTIL2, 0, 100);
    // transit the A to DA first to avoid too many error logs.
    UTIL1.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID, SyncReplicationState.DOWNGRADE_ACTIVE);
    HMaster master = UTIL2.getHBaseCluster().getMaster();
    ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor();
    // Enable test flags and then queue the procedure.
    ProcedureTestingUtility.waitNoProcedureRunning(procExec);
    ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                UTIL2.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID, SyncReplicationState.DOWNGRADE_ACTIVE);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }
    };
    t.start();
    UTIL2.waitFor(30000, () -> procExec.getProcedures().stream().anyMatch(p -> p instanceof TransitPeerSyncReplicationStateProcedure && !p.isFinished()));
    long procId = procExec.getProcedures().stream().filter(p -> p instanceof TransitPeerSyncReplicationStateProcedure && !p.isFinished()).mapToLong(Procedure::getProcId).min().getAsLong();
    MasterProcedureTestingUtility.testRecoveryAndDoubleExecution(procExec, procId);
    ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, false);
    assertEquals(SyncReplicationState.DOWNGRADE_ACTIVE, UTIL2.getAdmin().getReplicationPeerSyncReplicationState(PEER_ID));
    verify(UTIL2, 0, 100);
}
Also used : BeforeClass(org.junit.BeforeClass) SyncReplicationState(org.apache.hadoop.hbase.replication.SyncReplicationState) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) ProcedureTestingUtility(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility) LargeTests(org.apache.hadoop.hbase.testclassification.LargeTests) IOException(java.io.IOException) Test(org.junit.Test) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) MasterProcedureTestingUtility(org.apache.hadoop.hbase.master.procedure.MasterProcedureTestingUtility) Category(org.junit.experimental.categories.Category) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) UncheckedIOException(java.io.UncheckedIOException) SyncReplicationTestBase(org.apache.hadoop.hbase.replication.SyncReplicationTestBase) ProcedureExecutor(org.apache.hadoop.hbase.procedure2.ProcedureExecutor) MasterTests(org.apache.hadoop.hbase.testclassification.MasterTests) MasterProcedureConstants(org.apache.hadoop.hbase.master.procedure.MasterProcedureConstants) ClassRule(org.junit.ClassRule) HMaster(org.apache.hadoop.hbase.master.HMaster) Assert.assertEquals(org.junit.Assert.assertEquals) HMaster(org.apache.hadoop.hbase.master.HMaster) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Test(org.junit.Test)

Example 40 with MasterProcedureEnv

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

the class TestDeadServer method testCrashProcedureReplay.

@Test
public void testCrashProcedureReplay() throws Exception {
    HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
    final ProcedureExecutor<MasterProcedureEnv> pExecutor = master.getMasterProcedureExecutor();
    ServerCrashProcedure proc = new ServerCrashProcedure(pExecutor.getEnvironment(), hostname123, false, false);
    pExecutor.stop();
    ProcedureTestingUtility.submitAndWait(pExecutor, proc);
    assertTrue(master.getServerManager().areDeadServersInProgress());
    ProcedureTestingUtility.restart(pExecutor);
    ProcedureTestingUtility.waitProcedure(pExecutor, proc);
    assertFalse(master.getServerManager().areDeadServersInProgress());
}
Also used : ServerCrashProcedure(org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) Test(org.junit.Test)

Aggregations

MasterProcedureEnv (org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv)65 Test (org.junit.Test)48 TableName (org.apache.hadoop.hbase.TableName)42 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)39 IOException (java.io.IOException)16 ProcedureExecutor (org.apache.hadoop.hbase.procedure2.ProcedureExecutor)16 ArrayList (java.util.ArrayList)13 Path (org.apache.hadoop.fs.Path)13 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)13 MasterTests (org.apache.hadoop.hbase.testclassification.MasterTests)13 Bytes (org.apache.hadoop.hbase.util.Bytes)13 ClassRule (org.junit.ClassRule)13 Category (org.junit.experimental.categories.Category)13 BeforeClass (org.junit.BeforeClass)12 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)11 ServerName (org.apache.hadoop.hbase.ServerName)10 Procedure (org.apache.hadoop.hbase.procedure2.Procedure)10 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)10 MediumTests (org.apache.hadoop.hbase.testclassification.MediumTests)10 AfterClass (org.junit.AfterClass)10