/** * Wait until AM finishes the meta loading, i.e, the region states rebuilding. * @see #isMetaLoaded() * @see #waitMetaAssigned(Procedure, RegionInfo) */ public boolean waitMetaLoaded(Procedure<?> proc) { return metaLoadEvent.suspendIfNotReady(proc); }
public void suspend(Procedure<?> proc) { event.suspend(); event.suspendIfNotReady(proc); }
public void suspend(Procedure<?> proc) { event.suspend(); event.suspendIfNotReady(proc); }
public boolean waitInitialized(Procedure<?> proc) { return master.getInitializedEvent().suspendIfNotReady(proc); }
/** * Notice that this event does not mean the AM has already finished region state rebuilding. See * the comment of {@link #isMetaAssigned()} for more details. * @see #isMetaAssigned() */ public boolean waitMetaAssigned(Procedure<?> proc, RegionInfo regionInfo) { return getMetaAssignEvent(getMetaForRegion(regionInfo)).suspendIfNotReady(proc); }
@Override protected Procedure<MasterProcedureEnv>[] execute(final MasterProcedureEnv env) throws ProcedureSuspendedException { // Local master locks don't store any state, so on recovery, simply finish this procedure // immediately. if (recoveredMasterLock) return null; if (lockAcquireLatch != null) { lockAcquireLatch.countDown(); } if (unlock.get() || hasHeartbeatExpired()) { locked.set(false); LOG.debug((unlock.get()? "UNLOCKED " : "TIMED OUT ") + toString()); return null; } synchronized (event) { event.suspend(); event.suspendIfNotReady(this); setState(ProcedureProtos.ProcedureState.WAITING_TIMEOUT); } throw new ProcedureSuspendedException(); }
@Override protected synchronized Procedure<MasterProcedureEnv>[] execute(MasterProcedureEnv env) throws ProcedureYieldException, ProcedureSuspendedException, InterruptedException { if (dispatched) { if (succ) { return null; } // retry dispatched = false; } try { env.getRemoteDispatcher().addOperationToNode(targetServer, this); } catch (FailedRemoteDispatchException frde) { LOG.info("Can not add remote operation for refreshing peer {} for {} to {}, " + "this is usually because the server is already dead, " + "give up and mark the procedure as complete", peerId, type, targetServer, frde); return null; } dispatched = true; event = new ProcedureEvent<>(this); event.suspendIfNotReady(this); throw new ProcedureSuspendedException(); }
@Override protected Procedure<MasterProcedureEnv>[] execute(MasterProcedureEnv env) throws ProcedureYieldException, ProcedureSuspendedException, InterruptedException { if (dispatched) { if (succ) { return null; } dispatched = false; } try { env.getRemoteDispatcher().addOperationToNode(targetServer, this); } catch (FailedRemoteDispatchException frde) { LOG.warn("Can not add remote operation for switching rpc throttle to {} on {}", rpcThrottleEnabled, targetServer); return null; } dispatched = true; event = new ProcedureEvent<>(this); event.suspendIfNotReady(this); throw new ProcedureSuspendedException(); }
@Override protected Procedure<MasterProcedureEnv>[] execute(MasterProcedureEnv env) throws ProcedureYieldException, ProcedureSuspendedException, InterruptedException { if (dispatched) { if (succ) { return null; } // retry dispatched = false; } // Dispatch task to target server try { env.getRemoteDispatcher().addOperationToNode(targetServer, this); } catch (FailedRemoteDispatchException e) { LOG.warn("Can not add remote operation for replay wals {} on {} for peer id={}, " + "this usually because the server is already dead", wals, targetServer, peerId); // Return directly and the parent procedure will assign a new worker to replay wals return null; } dispatched = true; event = new ProcedureEvent<>(this); event.suspendIfNotReady(this); throw new ProcedureSuspendedException(); }
@Override protected Procedure<MasterProcedureEnv>[] execute(MasterProcedureEnv env) throws ProcedureYieldException, ProcedureSuspendedException, InterruptedException { if (dispatched) { if (success) { return null; } dispatched = false; } try { env.getRemoteDispatcher().addOperationToNode(worker, this); } catch (NoNodeDispatchException | NullTargetServerDispatchException | NoServerDispatchException e) { // When send to a wrong target server, it need construct a new SplitWALRemoteProcedure. // Thus return null for this procedure and let SplitWALProcedure to handle this. LOG.warn("dispatch WAL {} to {} failed, will retry on another server", walPath, worker, e); return null; } dispatched = true; event = new ProcedureEvent<>(this); event.suspendIfNotReady(this); throw new ProcedureSuspendedException(); }
@Override protected void afterReplay(final TestProcEnv env) { if (getState() == ProcedureState.WAITING_TIMEOUT) { event.suspend(); event.suspendIfNotReady(this); } }
@Override protected Procedure[] execute(final TestProcEnv env) throws ProcedureSuspendedException { LOG.info("EXECUTE " + this + " ntimeouts=" + ntimeouts); if (ntimeouts.get() > maxTimeouts) { setAbortFailure("test", "give up after " + ntimeouts.get()); return null; } event.suspend(); if (event.suspendIfNotReady(this)) { setState(ProcedureState.WAITING_TIMEOUT); throw new ProcedureSuspendedException(); } return null; }
@Override public void run() { while (true) { TestProcedureWithEvent proc = (TestProcedureWithEvent)sched.poll(); if (proc == null) continue; proc.getEvent().suspend(); waitQueue.add(proc); proc.getEvent().suspendIfNotReady(proc); LOG.debug("WAIT " + proc.getEvent()); if (waitCount.incrementAndGet() >= NRUNS) { break; } } } };
private void queueAssign(MasterProcedureEnv env, RegionStateNode regionNode) throws ProcedureSuspendedException { // Here the assumption is that, the region must be in CLOSED state, so the region location // will be null. And if we fail to open the region and retry here, the forceNewPlan will be // true, and also we will set the region location to null. boolean retain = false; if (!forceNewPlan) { if (assignCandidate != null) { retain = assignCandidate.equals(regionNode.getLastHost()); regionNode.setRegionLocation(assignCandidate); } else if (regionNode.getLastHost() != null) { retain = true; LOG.info("Setting lastHost as the region location {}", regionNode.getLastHost()); regionNode.setRegionLocation(regionNode.getLastHost()); } } LOG.info("Starting {}; {}; forceNewPlan={}, retain={}", this, regionNode.toShortString(), forceNewPlan, retain); env.getAssignmentManager().queueAssign(regionNode); setNextState(RegionStateTransitionState.REGION_STATE_TRANSITION_OPEN); if (regionNode.getProcedureEvent().suspendIfNotReady(this)) { throw new ProcedureSuspendedException(); } }
event.suspendIfNotReady(this); throw new ProcedureSuspendedException(); } finally {
@Test public void testSuspendedProcedure() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); queue.addBack( new TestTableProcedure(1, tableName, TableProcedureInterface.TableOperationType.READ)); queue.addBack( new TestTableProcedure(2, tableName, TableProcedureInterface.TableOperationType.READ)); Procedure<?> proc = queue.poll(); assertEquals(1, proc.getProcId()); // suspend ProcedureEvent<?> event = new ProcedureEvent<>("testSuspendedProcedureEvent"); assertEquals(true, event.suspendIfNotReady(proc)); proc = queue.poll(); assertEquals(2, proc.getProcId()); assertEquals(null, queue.poll(0)); // resume event.wake(queue); proc = queue.poll(); assertEquals(1, proc.getProcId()); assertEquals(null, queue.poll(0)); }
@Override protected void afterReplay(final TestProcEnv env) { if (getState() == ProcedureState.WAITING_TIMEOUT) { event.suspend(); event.suspendIfNotReady(this); } }
@Override protected void afterReplay(final TestProcEnv env) { if (getState() == ProcedureState.WAITING_TIMEOUT) { event.suspend(); event.suspendIfNotReady(this); } }
@Override protected Procedure[] execute(final TestProcEnv env) throws ProcedureSuspendedException { LOG.info("EXECUTE " + this + " ntimeouts=" + ntimeouts); if (ntimeouts.get() > maxTimeouts) { setAbortFailure("test", "give up after " + ntimeouts.get()); return null; } event.suspend(); if (event.suspendIfNotReady(this)) { setState(ProcedureState.WAITING_TIMEOUT); throw new ProcedureSuspendedException(); } return null; }
@Override protected Procedure[] execute(final TestProcEnv env) throws ProcedureSuspendedException { LOG.info("EXECUTE " + this + " ntimeouts=" + ntimeouts); if (ntimeouts.get() > maxTimeouts) { setAbortFailure("test", "give up after " + ntimeouts.get()); return null; } event.suspend(); if (event.suspendIfNotReady(this)) { setState(ProcedureState.WAITING_TIMEOUT); throw new ProcedureSuspendedException(); } return null; }