protected synchronized void setFailure(final RemoteProcedureException exception) { this.exception = exception; if (!isFinished()) { setState(ProcedureState.FAILED); } }
private boolean isRootFinished(Procedure<?> proc) { Procedure<?> rootProc = procedures.get(proc.getRootProcId()); return rootProc == null || rootProc.isFinished(); }
final void restoreLock(TEnvironment env) { if (!lockedWhenLoading) { LOG.debug("{} didn't hold the lock before restarting, skip acquiring lock.", this); return; } if (isFinished()) { LOG.debug("{} is already finished, skip acquiring lock.", this); return; } if (isBypass()) { LOG.debug("{} is already bypassed, skip acquiring lock.", this); return; } // this can happen if the parent stores the sub procedures but before it can // release its lock, the master restarts if (getState() == ProcedureState.WAITING && !holdLock(env)) { LOG.debug("{} is in WAITING STATE, and holdLock=false, skip acquiring lock.", this); lockedWhenLoading = false; return; } LOG.debug("{} held the lock before restarting, call acquireLock to restore it.", this); LockState state = acquireLock(env); assert state == LockState.LOCK_ACQUIRED; }
private void releaseLock(Procedure<TEnvironment> proc, boolean force) { TEnvironment env = getEnvironment(); // For how the framework works, we know that we will always have the lock // when we call releaseLock(), so we can avoid calling proc.hasLock() if (force || !proc.holdLock(env) || proc.isFinished()) { proc.doReleaseLock(env, store); } }
Procedure<TEnvironment> proc = procedures.get(procId); if (proc != null) { if (proc.isFinished() && proc.hasParent() && isRootFinished(proc)) { LOG.debug("Procedure {} has already been finished and parent is succeeded," + " skip force updating", proc);
private void updateStoreOnExec(RootProcedureState<TEnvironment> procStack, Procedure<TEnvironment> procedure, Procedure<TEnvironment>[] subprocs) { if (subprocs != null && !procedure.isFailed()) { if (LOG.isTraceEnabled()) { LOG.trace("Stored " + procedure + ", children " + Arrays.toString(subprocs)); } store.insert(procedure, subprocs); } else { LOG.trace("Store update {}", procedure); if (procedure.isFinished() && !procedure.hasParent()) { // remove child procedures final long[] childProcIds = procStack.getSubprocedureIds(); if (childProcIds != null) { store.delete(procedure, childProcIds); for (int i = 0; i < childProcIds.length; ++i) { procedures.remove(childProcIds[i]); } } else { store.update(procedure); } } else { store.update(procedure); } } }
private boolean shouldSubmitSCP(ServerName serverName) { // check if there is already a SCP of this server running List<Procedure<MasterProcedureEnv>> procedures = master.getMasterProcedureExecutor().getProcedures(); for (Procedure<MasterProcedureEnv> procedure : procedures) { if (procedure instanceof ServerCrashProcedure) { if (serverName.compareTo(((ServerCrashProcedure) procedure).getServerName()) == 0 && !procedure.isFinished()) { LOG.info("there is already a SCP of this server {} running, pid {}", serverName, procedure.getProcId()); return false; } } } return true; } }
@Override public void postExecuteProcedures(ObserverContext<RegionServerCoprocessorEnvironment> ctx) throws IOException { synchronized (HaltCP.class) { if (!HALT) { return; } UTIL1.getMiniHBaseCluster().getMaster().getProcedures().stream() .filter(p -> p instanceof TransitPeerSyncReplicationStateProcedure) .filter(p -> !p.isFinished()).map(p -> (TransitPeerSyncReplicationStateProcedure) p) .findFirst().ifPresent(proc -> { // this is the next state of REFRESH_PEER_SYNC_REPLICATION_STATE_ON_RS_BEGIN_VALUE if (proc.getCurrentStateId() == REOPEN_ALL_REGIONS_IN_PEER_VALUE) { // tell the main thread to start a new region server ARRIVE.countDown(); try { // wait for the region server to online RESUME.await(); } catch (InterruptedException e) { throw new RuntimeException(e); } HALT = false; } }); } } }
private void executeProcedure(Procedure<TEnvironment> proc) { if (proc.isFinished()) { LOG.debug("{} is already finished, skipping execution", proc); return;
if (procedure.isFinished()) { LOG.debug("{} is already finished, skipping bypass", procedure); return false;
@AfterClass public static void tearDown() throws Exception { // Wait the SCP of abort rs to finish UTIL.waitFor(30000, () -> UTIL.getMiniHBaseCluster().getMaster().getProcedures().stream() .filter(p -> p instanceof ServerCrashProcedure && p.isFinished()).count() > 0); UTIL.getAdmin().disableTable(TABLE_NAME); UTIL.getAdmin().deleteTable(TABLE_NAME); UTIL.shutdownMiniCluster(); }
if (!proc.isFinished() && proc.isYieldAfterExecutionStep(getEnvironment())) { return LockState.LOCK_YIELD_WAIT;
@Test public void testCleanupMetaWAL() throws Exception { TEST_UTIL.createTable(TableName.valueOf("test"), "cf"); HRegionServer serverWithMeta = TEST_UTIL.getMiniHBaseCluster() .getRegionServer(TEST_UTIL.getMiniHBaseCluster().getServerWithMeta()); TEST_UTIL.getAdmin() .move(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes(), null); LOG.info("KILL"); TEST_UTIL.getMiniHBaseCluster().killRegionServer(serverWithMeta.getServerName()); LOG.info("WAIT"); TEST_UTIL.waitFor(30000, () -> TEST_UTIL.getMiniHBaseCluster().getMaster().getProcedures().stream() .filter(p -> p instanceof ServerCrashProcedure && p.isFinished()).count() > 0); LOG.info("DONE WAITING"); MasterFileSystem fs = TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterFileSystem(); Path walPath = new Path(fs.getWALRootDir(), HConstants.HREGION_LOGDIR_NAME); for (FileStatus status : FSUtils.listStatus(fs.getFileSystem(), walPath)) { if (status.getPath().toString().contains(SPLITTING_EXT)) { fail("Should not have splitting wal dir here:" + status); } } } }
TransitRegionStateProcedure proc = procExec.getProcedures().stream().filter(p -> p instanceof TransitRegionStateProcedure) .filter(p -> !p.isFinished()).map(p -> (TransitRegionStateProcedure) p).findAny().get();
TransitRegionStateProcedure proc = procExec.getProcedures().stream().filter(p -> p instanceof TransitRegionStateProcedure) .filter(p -> !p.isFinished()).map(p -> (TransitRegionStateProcedure) p).findAny().get(); IdLock procExecLock = procExec.getProcExecutionLock();
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()));
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);
() -> procB.acquireLock(pExecutor.getEnvironment()) == Procedure.LockState.LOCK_ACQUIRED); LOG.info("when procedure B get the lock, procedure A should be finished"); assertTrue(procA.isFinished());
&& ((ServerCrashProcedure) p).getServerName().equals(testServer)) .findAny().get(); UTIL.waitFor(20000, () -> procedure.isFinished()); LOG.info("even when the SCP is finished, the duplicate SCP should not be scheduled for {}", testServer);
@Test public void test() throws Exception { TestProcedure proc = new TestProcedure(); long procId = procExecutor.submitProcedure(proc); htu.waitFor(30000, () -> proc.isWaiting()); ProcedureTestingUtility.restart(procExecutor); htu.waitFor(30000, () -> { Procedure<?> p = procExecutor.getProcedure(procId); return p.isWaiting() || p.isFinished(); }); assertFalse(procExecutor.isFinished(procId)); ProcedureTestingUtility.restart(procExecutor); htu.waitFor(30000, () -> procExecutor.isFinished(procId)); Procedure<ProcEnv> p = procExecutor.getResult(procId); assertTrue(p.isSuccess()); } }