/** * 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); }
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 void countDownChildren(RootProcedureState<TEnvironment> procStack, Procedure<TEnvironment> procedure) { Procedure<TEnvironment> parent = procedures.get(procedure.getParentProcId()); if (parent == null) { assert procStack.isRollingback(); return; } // If this procedure is the last child awake the parent procedure if (parent.tryRunnable()) { // If we succeeded in making the parent runnable -- i.e. all of its // children have completed, move parent to front of the queue. store.update(parent); scheduler.addFront(parent); LOG.info("Finished subprocedure(s) of " + parent + "; resume parent processing."); return; } }
/** * Internal method called by the ProcedureExecutor that starts the user-level code acquireLock(). */ final LockState doAcquireLock(TEnvironment env, ProcedureStore store) { if (waitInitialized(env)) { return LockState.LOCK_EVENT_WAIT; } if (lockedWhenLoading) { // reset it so we will not consider it anymore lockedWhenLoading = false; locked = true; // Here we return without persist the locked state, as lockedWhenLoading is true means // that the locked field of the procedure stored in procedure store is true, so we do not need // to store it again. return LockState.LOCK_ACQUIRED; } LockState state = acquireLock(env); if (state == LockState.LOCK_ACQUIRED) { locked = true; // persist that we have held the lock. This must be done before we actually execute the // procedure, otherwise when restarting, we may consider the procedure does not have a lock, // but it may have already done some changes as we have already executed it, and if another // procedure gets the lock, then the semantic will be broken if the holdLock is true, as we do // not expect that another procedure can be executed in the middle. store.update(this); } return state; }
store.update(proc); } finally { procExecutionLock.releaseLockEntry(lockEntry);
private void cleanupAfterRollbackOneStep(Procedure<TEnvironment> proc) { if (proc.removeStackIndex()) { if (!proc.isSuccess()) { proc.setState(ProcedureState.ROLLEDBACK); } // update metrics on finishing the procedure (fail) proc.updateMetricsOnFinish(getEnvironment(), proc.elapsedTime(), false); if (proc.hasParent()) { store.delete(proc.getProcId()); procedures.remove(proc.getProcId()); } else { final long[] childProcIds = rollbackStack.get(proc.getProcId()).getSubprocedureIds(); if (childProcIds != null) { store.delete(proc, childProcIds); } else { store.update(proc); } } } else { store.update(proc); } }
protected void executeTimedoutProcedure(Procedure<TEnvironment> proc) { // The procedure received a timeout. if the procedure itself does not handle it, // call abort() and add the procedure back in the queue for rollback. if (proc.setTimeoutFailure(executor.getEnvironment())) { long rootProcId = executor.getRootProcedureId(proc); RootProcedureState<TEnvironment> procStack = executor.getProcStack(rootProcId); procStack.abort(); executor.getStore().update(proc); executor.getScheduler().addFront(proc); } } }
exception = procStack.getException(); rootProc.setFailure(exception); store.update(rootProc);
/** * 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); }
private void countDownChildren(final RootProcedureState procStack, final Procedure procedure) { final Procedure parent = procedures.get(procedure.getParentProcId()); if (parent == null) { assert procStack.isRollingback(); return; } // If this procedure is the last child awake the parent procedure if (parent.tryRunnable()) { // If we succeeded in making the parent runnable -- i.e. all of its // children have completed, move parent to front of the queue. store.update(parent); scheduler.addFront(parent); LOG.info("Finished subprocedure(s) of " + parent + "; resume parent processing."); return; } }
private void updateStoreOnExec(final RootProcedureState procStack, final Procedure procedure, final Procedure[] subprocs) { if (subprocs != null && !procedure.isFailed()) { if (LOG.isTraceEnabled()) { LOG.trace("Stored " + procedure + ", children " + Arrays.toString(subprocs)); } store.insert(procedure, subprocs); } else { if (LOG.isTraceEnabled()) { 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 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); } } }
/** * Internal method called by the ProcedureExecutor that starts the user-level code acquireLock(). */ final LockState doAcquireLock(TEnvironment env, ProcedureStore store) { if (waitInitialized(env)) { return LockState.LOCK_EVENT_WAIT; } if (lockedWhenLoading) { // reset it so we will not consider it anymore lockedWhenLoading = false; locked = true; // Here we return without persist the locked state, as lockedWhenLoading is true means // that the locked field of the procedure stored in procedure store is true, so we do not need // to store it again. return LockState.LOCK_ACQUIRED; } LockState state = acquireLock(env); if (state == LockState.LOCK_ACQUIRED) { locked = true; // persist that we have held the lock. This must be done before we actually execute the // procedure, otherwise when restarting, we may consider the procedure does not have a lock, // but it may have already done some changes as we have already executed it, and if another // procedure gets the lock, then the semantic will be broken if the holdLock is true, as we do // not expect that another procedure can be executed in the middle. store.update(this); } return state; }
private void countDownChildren(RootProcedureState<TEnvironment> procStack, Procedure<TEnvironment> procedure) { Procedure<TEnvironment> parent = procedures.get(procedure.getParentProcId()); if (parent == null) { assert procStack.isRollingback(); return; } // If this procedure is the last child awake the parent procedure if (parent.tryRunnable()) { // If we succeeded in making the parent runnable -- i.e. all of its // children have completed, move parent to front of the queue. store.update(parent); scheduler.addFront(parent); LOG.info("Finished subprocedure pid={}, resume processing parent {}", procedure.getProcId(), parent); return; } }
store.update(proc); } finally { procExecutionLock.releaseLockEntry(lockEntry);
private void cleanupAfterRollbackOneStep(Procedure<TEnvironment> proc) { if (proc.removeStackIndex()) { if (!proc.isSuccess()) { proc.setState(ProcedureState.ROLLEDBACK); } // update metrics on finishing the procedure (fail) proc.updateMetricsOnFinish(getEnvironment(), proc.elapsedTime(), false); if (proc.hasParent()) { store.delete(proc.getProcId()); procedures.remove(proc.getProcId()); } else { final long[] childProcIds = rollbackStack.get(proc.getProcId()).getSubprocedureIds(); if (childProcIds != null) { store.delete(proc, childProcIds); } else { store.update(proc); } } } else { store.update(proc); } }
protected void executeTimedoutProcedure(Procedure<TEnvironment> proc) { // The procedure received a timeout. if the procedure itself does not handle it, // call abort() and add the procedure back in the queue for rollback. if (proc.setTimeoutFailure(executor.getEnvironment())) { long rootProcId = executor.getRootProcedureId(proc); RootProcedureState<TEnvironment> procStack = executor.getProcStack(rootProcId); procStack.abort(); executor.getStore().update(proc); executor.getScheduler().addFront(proc); } } }
private void executeTimedoutProcedure(Procedure proc) { // The procedure received a timeout. if the procedure itself does not handle it, // call abort() and add the procedure back in the queue for rollback. if (proc.setTimeoutFailure(executor.getEnvironment())) { long rootProcId = executor.getRootProcedureId(proc); RootProcedureState procStack = executor.getProcStack(rootProcId); procStack.abort(); executor.getStore().update(proc); executor.getScheduler().addFront(proc); } } }