/** * Called from {@link #toString()} when interpolating {@link Procedure} State. Allows decorating * generic Procedure State with Procedure particulars. * @param builder Append current {@link ProcedureState} */ protected void toStringState(StringBuilder builder) { builder.append(getState()); }
/** * Try to set this procedure into RUNNABLE state. * Succeeds if all subprocedures/children are done. * @return True if we were able to move procedure to RUNNABLE state. */ synchronized boolean tryRunnable() { // Don't use isWaiting in the below; it returns true for WAITING and WAITING_TIMEOUT if (getState() == ProcedureState.WAITING && childrenCountDown()) { setState(ProcedureState.RUNNABLE); return true; } else { return false; } }
/** * Internal method called by the ProcedureExecutor that starts the user-level code releaseLock(). */ final void doReleaseLock(TEnvironment env, ProcedureStore store) { locked = false; // persist that we have released the lock. This must be done before we actually release the // lock. Another procedure may take this lock immediately after we release the lock, and if we // crash before persist the information that we have already released the lock, then when // restarting there will be two procedures which both have the lock and cause problems. if (getState() != ProcedureState.ROLLEDBACK) { // If the state is ROLLEDBACK, it means that we have already deleted the procedure from // procedure store, so do not need to log the release operation any more. store.update(this); } releaseLock(env); }
public static String describe(Procedure<?> proc) { Map<String, Object> description = new LinkedHashMap<>(); description.put("ID", proc.getProcId()); description.put("PARENT_ID", proc.getParentProcId()); description.put("STATE", proc.getState()); description.put("OWNER", proc.getOwner()); description.put("TYPE", proc.getProcName()); description.put("START_TIME", new Date(proc.getSubmittedTime())); description.put("LAST_UPDATE", new Date(proc.getLastUpdate())); if (proc.isFailed()) { description.put("ERRORS", MasterProcedureUtil.unwrapRemoteIOException(proc).getMessage()); } description.put("PARAMETERS", parametersToObject(proc)); return JRubyFormat.print(description); }
/** * Called on store load by the ProcedureExecutor to load part of the stack. * * Each procedure has its own stack-positions. Which means we have to write * to the store only the Procedure we executed, and nothing else. * on load we recreate the full stack by aggregating each procedure stack-positions. */ protected synchronized void loadStack(Procedure<TEnvironment> proc) { addSubProcedure(proc); int[] stackIndexes = proc.getStackIndexes(); if (stackIndexes != null) { if (subprocStack == null) { subprocStack = new ArrayList<>(); } int diff = (1 + stackIndexes[stackIndexes.length - 1]) - subprocStack.size(); if (diff > 0) { subprocStack.ensureCapacity(1 + stackIndexes[stackIndexes.length - 1]); while (diff-- > 0) subprocStack.add(null); } for (int i = 0; i < stackIndexes.length; ++i) { subprocStack.set(stackIndexes[i], proc); } } if (proc.getState() == ProcedureState.ROLLEDBACK) { state = State.ROLLINGBACK; } else if (proc.isFailed()) { state = State.FAILED; } }
public void add(Procedure<TEnvironment> procedure) { assert procedure.getState() == ProcedureState.WAITING_TIMEOUT; LOG.info("ADDED {}; timeout={}, timestamp={}", procedure, procedure.getTimeout(), procedure.getTimeoutTimestamp()); queue.add(new DelayedProcedure<>(procedure)); }
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; }
@Override public Boolean evaluate() throws IOException { if (!procExec.isRunning()) { return true; } ProcedureState state = proc.getState(); if (state == ProcedureState.INITIALIZING || state == ProcedureState.RUNNABLE) { // under these states the procedure may have not been added to procExec yet, so do not // use isFinished to test whether it is finished, as this method will just check if the // procedure is in the running procedure list return false; } return procExec.isFinished(proc.getProcId()); } });
private Procedure<TEnvironment> prepareProcedure(Procedure<TEnvironment> proc) { Preconditions.checkArgument(proc.getState() == ProcedureState.INITIALIZING); Preconditions.checkArgument(!proc.hasParent(), "unexpected parent", proc); if (this.checkOwnerSet) { Preconditions.checkArgument(proc.hasOwner(), "missing owner"); } return proc; }
if (procedure.hasParent() && procedure.getState() != ProcedureState.RUNNABLE && procedure.getState() != ProcedureState.WAITING && procedure.getState() != ProcedureState.WAITING_TIMEOUT) { LOG.debug("Bypassing procedures in RUNNABLE, WAITING and WAITING_TIMEOUT states " + "(with no parent), {}", if (procedure.getState() == ProcedureState.WAITING) { procedure.setState(ProcedureState.RUNNABLE); store.update(procedure); if (procedure.getState() == ProcedureState.WAITING_TIMEOUT) { LOG.debug("transform procedure {} from WAITING_TIMEOUT to RUNNABLE", procedure); if (timeoutExecutor.remove(procedure)) {
public static <TEnv> void waitProcedure(ProcedureExecutor<TEnv> procExecutor, Procedure proc) { while (proc.getState() == ProcedureState.INITIALIZING) { Threads.sleepWithoutInterrupt(250); } waitProcedure(procExecutor, proc.getProcId()); }
@Test public void testFailCreateTable() throws Exception { conf.set(MASTER_COPROCESSOR_CONF_KEY, CreateFailObserver.class.getName()); TEST_UTIL.startMiniCluster(3); try { TEST_UTIL.createTable(TABLE, FAMILY); } catch (AccessDeniedException e) { LOG.debug("Ignoring exception: ", e); Thread.sleep(evictionDelay * 3); } List<Procedure<MasterProcedureEnv>> procedureInfos = TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor().getProcedures(); for (Procedure procedureInfo : procedureInfos) { if (procedureInfo.getProcName().equals("CreateTableProcedure") && procedureInfo.getState() == ProcedureProtos.ProcedureState.ROLLEDBACK) { fail("Found procedure " + procedureInfo + " that hasn't been cleaned up"); } } }
assert proc.getState() == ProcedureState.RUNNABLE : proc;
@Test public void testFailCreateTableAction() throws Exception { conf.set(MASTER_COPROCESSOR_CONF_KEY, CreateFailObserverHandler.class.getName()); TEST_UTIL.startMiniCluster(3); try { TEST_UTIL.createTable(TABLE, FAMILY); fail("Table shouldn't be created"); } catch (AccessDeniedException e) { LOG.debug("Ignoring exception: ", e); Thread.sleep(evictionDelay * 3); } List<Procedure<MasterProcedureEnv>> procedureInfos = TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor().getProcedures(); for (Procedure procedureInfo : procedureInfos) { if (procedureInfo.getProcName().equals("CreateTableProcedure") && procedureInfo.getState() == ProcedureProtos.ProcedureState.ROLLEDBACK) { fail("Found procedure " + procedureInfo + " that hasn't been cleaned up"); } } }
Preconditions.checkArgument(procedure.getState() == ProcedureState.RUNNABLE, "NOT RUNNABLE! " + procedure.toString()); collect(Collectors.toList()).toString())); } else if (procedure.getState() == ProcedureState.WAITING_TIMEOUT) { LOG.trace("Added to timeoutExecutor {}", procedure); timeoutExecutor.add(procedure);
out.print( proc.hasParent() ? proc.getParentProcId() : "" ); out.write("</td>\n <td>"); out.print( escapeXml(proc.getState().toString() + (proc.isBypass() ? "(Bypass)" : "")) ); out.write("</td>\n <td>"); out.print( proc.hasOwner() ? escapeXml(proc.getOwner()) : "" );
.setClassName(proc.getClass().getName()) .setProcId(proc.getProcId()) .setState(proc.getState()) .setSubmittedTime(proc.getSubmittedTime()) .setLastUpdate(proc.getLastUpdate());