Search in sources :

Example 11 with TransitRegionStateProcedure

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

the class MasterProcedureTestingUtility method restartMasterProcedureExecutor.

public static void restartMasterProcedureExecutor(ProcedureExecutor<MasterProcedureEnv> procExec) throws Exception {
    final MasterProcedureEnv env = procExec.getEnvironment();
    final HMaster master = (HMaster) env.getMasterServices();
    ProcedureTestingUtility.restart(procExec, true, true, // stop services
    new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            AssignmentManager am = env.getAssignmentManager();
            // try to simulate a master restart by removing the ServerManager states about seqIDs
            for (RegionState regionState : am.getRegionStates().getRegionStates()) {
                env.getMasterServices().getServerManager().removeRegion(regionState.getRegion());
            }
            am.stop();
            master.setInitialized(false);
            return null;
        }
    }, // setup RIT before starting workers
    new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            AssignmentManager am = env.getAssignmentManager();
            am.start();
            // just follow the same way with HMaster.finishActiveMasterInitialization. See the
            // comments there
            am.setupRIT(procExec.getActiveProceduresNoCopy().stream().filter(p -> !p.isSuccess()).filter(p -> p instanceof TransitRegionStateProcedure).map(p -> (TransitRegionStateProcedure) p).collect(Collectors.toList()));
            return null;
        }
    }, // restart services
    new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            AssignmentManager am = env.getAssignmentManager();
            try {
                am.joinCluster();
                am.wakeMetaLoadedEvent();
                master.setInitialized(true);
            } catch (Exception e) {
                LOG.warn("Failed to load meta", e);
            }
            return null;
        }
    });
}
Also used : CatalogFamilyFormat(org.apache.hadoop.hbase.CatalogFamilyFormat) Result(org.apache.hadoop.hbase.client.Result) FileSystem(org.apache.hadoop.fs.FileSystem) RegionLocations(org.apache.hadoop.hbase.RegionLocations) LoggerFactory(org.slf4j.LoggerFactory) RegionState(org.apache.hadoop.hbase.master.RegionState) MD5Hash(org.apache.hadoop.hbase.util.MD5Hash) ProcedureExecutor(org.apache.hadoop.hbase.procedure2.ProcedureExecutor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Path(org.apache.hadoop.fs.Path) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) BufferedMutator(org.apache.hadoop.hbase.client.BufferedMutator) Durability(org.apache.hadoop.hbase.client.Durability) TableStateManager(org.apache.hadoop.hbase.master.TableStateManager) CommonFSUtils(org.apache.hadoop.hbase.util.CommonFSUtils) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) Collectors(java.util.stream.Collectors) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) StoreFileTrackerFactory(org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory) EnvironmentEdgeManager(org.apache.hadoop.hbase.util.EnvironmentEdgeManager) TRACKER_IMPL(org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory.TRACKER_IMPL) MetaTableAccessor(org.apache.hadoop.hbase.MetaTableAccessor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) HMaster(org.apache.hadoop.hbase.master.HMaster) FSUtils(org.apache.hadoop.hbase.util.FSUtils) StateMachineProcedure(org.apache.hadoop.hbase.procedure2.StateMachineProcedure) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) ModifyRegionUtils(org.apache.hadoop.hbase.util.ModifyRegionUtils) Callable(java.util.concurrent.Callable) SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) TableState(org.apache.hadoop.hbase.client.TableState) TreeSet(java.util.TreeSet) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) ServerName(org.apache.hadoop.hbase.ServerName) Bytes(org.apache.hadoop.hbase.util.Bytes) TableName(org.apache.hadoop.hbase.TableName) Logger(org.slf4j.Logger) Put(org.apache.hadoop.hbase.client.Put) Assert.assertTrue(org.junit.Assert.assertTrue) ProcedureTestingUtility(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility) IOException(java.io.IOException) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) ClientMetaTableAccessor(org.apache.hadoop.hbase.ClientMetaTableAccessor) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) Admin(org.apache.hadoop.hbase.client.Admin) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) TransitRegionStateProcedure(org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure) Connection(org.apache.hadoop.hbase.client.Connection) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Assert.assertEquals(org.junit.Assert.assertEquals) RegionState(org.apache.hadoop.hbase.master.RegionState) TransitRegionStateProcedure(org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure) HMaster(org.apache.hadoop.hbase.master.HMaster) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) IOException(java.io.IOException)

Example 12 with TransitRegionStateProcedure

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

the class TestReopenTableRegionsProcedureBackoff method testRetryBackoff.

@Test
public void testRetryBackoff() throws IOException, InterruptedException {
    AssignmentManager am = UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager();
    ProcedureExecutor<MasterProcedureEnv> procExec = UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor();
    RegionInfo regionInfo = UTIL.getAdmin().getRegions(TABLE_NAME).get(0);
    RegionStateNode regionNode = am.getRegionStates().getRegionStateNode(regionInfo);
    // just a dummy one
    TransitRegionStateProcedure trsp = TransitRegionStateProcedure.unassign(procExec.getEnvironment(), regionInfo);
    long openSeqNum;
    regionNode.lock();
    try {
        openSeqNum = regionNode.getOpenSeqNum();
        // make a fake state to let the procedure wait.
        regionNode.setState(State.OPENING);
        regionNode.setOpenSeqNum(-1L);
        regionNode.setProcedure(trsp);
    } finally {
        regionNode.unlock();
    }
    ReopenTableRegionsProcedure proc = new ReopenTableRegionsProcedure(TABLE_NAME);
    procExec.submitProcedure(proc);
    UTIL.waitFor(10000, () -> proc.getState() == ProcedureState.WAITING_TIMEOUT);
    long oldTimeout = 0;
    int timeoutIncrements = 0;
    for (; ; ) {
        long timeout = proc.getTimeout();
        if (timeout > oldTimeout) {
            LOG.info("Timeout incremented, was {}, now is {}, increments={}", timeout, oldTimeout, timeoutIncrements);
            oldTimeout = timeout;
            timeoutIncrements++;
            if (timeoutIncrements > 3) {
                // If we incremented at least twice, break; the backoff is working.
                break;
            }
        }
        Thread.sleep(1000);
    }
    regionNode.lock();
    try {
        // reset to the correct state
        regionNode.setState(State.OPEN);
        regionNode.setOpenSeqNum(openSeqNum);
        regionNode.unsetProcedure(trsp);
    } finally {
        regionNode.unlock();
    }
    ProcedureSyncWait.waitForProcedureToComplete(procExec, proc, 60000);
    assertTrue(regionNode.getOpenSeqNum() > openSeqNum);
}
Also used : TransitRegionStateProcedure(org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure) 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 13 with TransitRegionStateProcedure

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

the class TestServerCrashProcedureCarryingMetaStuck method test.

@Test
public void test() throws Exception {
    RegionServerThread rsThread = null;
    for (RegionServerThread t : UTIL.getMiniHBaseCluster().getRegionServerThreads()) {
        if (!t.getRegionServer().getRegions(TableName.META_TABLE_NAME).isEmpty()) {
            rsThread = t;
            break;
        }
    }
    HRegionServer rs = rsThread.getRegionServer();
    RegionInfo hri = rs.getRegions(TableName.META_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)

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