Search in sources :

Example 1 with LockState

use of org.apache.hadoop.hbase.procedure2.Procedure.LockState in project hbase by apache.

the class ProcedureExecutor method executeRollback.

/**
   * Execute the rollback of the full procedure stack.
   * Once the procedure is rolledback, the root-procedure will be visible as
   * finished to user, and the result will be the fatal exception.
   */
private LockState executeRollback(final long rootProcId, final RootProcedureState procStack) {
    final Procedure rootProc = procedures.get(rootProcId);
    RemoteProcedureException exception = rootProc.getException();
    if (exception == null) {
        exception = procStack.getException();
        rootProc.setFailure(exception);
        store.update(rootProc);
    }
    final List<Procedure> subprocStack = procStack.getSubproceduresStack();
    assert subprocStack != null : "Called rollback with no steps executed rootProc=" + rootProc;
    int stackTail = subprocStack.size();
    boolean reuseLock = false;
    while (stackTail-- > 0) {
        final Procedure proc = subprocStack.get(stackTail);
        LockState lockState;
        if (!reuseLock && (lockState = acquireLock(proc)) != LockState.LOCK_ACQUIRED) {
            // queue waiting for the lock availability
            return lockState;
        }
        lockState = executeRollback(proc);
        boolean abortRollback = lockState != LockState.LOCK_ACQUIRED;
        abortRollback |= !isRunning() || !store.isRunning();
        // If the next procedure is the same to this one
        // (e.g. StateMachineProcedure reuse the same instance)
        // we can avoid to lock/unlock each step
        reuseLock = stackTail > 0 && (subprocStack.get(stackTail - 1) == proc) && !abortRollback;
        if (!reuseLock) {
            releaseLock(proc, false);
        }
        // useful to test the procedure recovery.
        if (abortRollback) {
            return lockState;
        }
        subprocStack.remove(stackTail);
        // if the procedure is kind enough to pass the slot to someone else, yield
        if (proc.isYieldAfterExecutionStep(getEnvironment())) {
            return LockState.LOCK_YIELD_WAIT;
        }
        if (proc != rootProc) {
            execCompletionCleanup(proc);
        }
    }
    // Finalize the procedure state
    LOG.info("Rolled back " + rootProc + " exec-time=" + StringUtils.humanTimeDiff(rootProc.elapsedTime()) + " exception=" + exception.getMessage());
    procedureFinished(rootProc);
    return LockState.LOCK_ACQUIRED;
}
Also used : LockState(org.apache.hadoop.hbase.procedure2.Procedure.LockState)

Aggregations

LockState (org.apache.hadoop.hbase.procedure2.Procedure.LockState)1