Search in sources :

Example 1 with RemoteProcedureException

use of org.apache.hadoop.hbase.procedure2.RemoteProcedureException 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)

Example 2 with RemoteProcedureException

use of org.apache.hadoop.hbase.procedure2.RemoteProcedureException 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(long rootProcId, RootProcedureState<TEnvironment> procStack) {
    Procedure<TEnvironment> rootProc = procedures.get(rootProcId);
    RemoteProcedureException exception = rootProc.getException();
    // rolling back because the subprocedure does. Clarify.
    if (exception == null) {
        exception = procStack.getException();
        rootProc.setFailure(exception);
        store.update(rootProc);
    }
    List<Procedure<TEnvironment>> subprocStack = procStack.getSubproceduresStack();
    assert subprocStack != null : "Called rollback with no steps executed rootProc=" + rootProc;
    int stackTail = subprocStack.size();
    while (stackTail-- > 0) {
        Procedure<TEnvironment> proc = subprocStack.get(stackTail);
        IdLock.Entry lockEntry = null;
        // prevent race between us and the force update thread.
        if (!procExecutionLock.isHeldByCurrentThread(proc.getProcId())) {
            try {
                lockEntry = procExecutionLock.getLockEntry(proc.getProcId());
            } catch (IOException e) {
                // can only happen if interrupted, so not a big deal to propagate it
                throw new UncheckedIOException(e);
            }
        }
        try {
            // fact these procedures can not be rolled back...).
            if (proc.isSuccess()) {
                // Just do the cleanup work, without actually executing the rollback
                subprocStack.remove(stackTail);
                cleanupAfterRollbackOneStep(proc);
                continue;
            }
            LockState lockState = acquireLock(proc);
            if (lockState != LockState.LOCK_ACQUIRED) {
                // queue waiting for the lock availability
                return lockState;
            }
            lockState = executeRollback(proc);
            releaseLock(proc, false);
            boolean abortRollback = lockState != LockState.LOCK_ACQUIRED;
            abortRollback |= !isRunning() || !store.isRunning();
            // useful to test the procedure recovery.
            if (abortRollback) {
                return lockState;
            }
            subprocStack.remove(stackTail);
            // if the proc is already finished, do not yield
            if (!proc.isFinished() && proc.isYieldAfterExecutionStep(getEnvironment())) {
                return LockState.LOCK_YIELD_WAIT;
            }
            if (proc != rootProc) {
                execCompletionCleanup(proc);
            }
        } finally {
            if (lockEntry != null) {
                procExecutionLock.releaseLockEntry(lockEntry);
            }
        }
    }
    // Finalize the procedure state
    LOG.info("Rolled back {} exec-time={}", rootProc, StringUtils.humanTimeDiff(rootProc.elapsedTime()));
    procedureFinished(rootProc);
    return LockState.LOCK_ACQUIRED;
}
Also used : IdLock(org.apache.hadoop.hbase.util.IdLock) UncheckedIOException(java.io.UncheckedIOException) IllegalArgumentIOException(org.apache.hadoop.hbase.exceptions.IllegalArgumentIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) LockState(org.apache.hadoop.hbase.procedure2.Procedure.LockState)

Aggregations

LockState (org.apache.hadoop.hbase.procedure2.Procedure.LockState)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 IllegalArgumentIOException (org.apache.hadoop.hbase.exceptions.IllegalArgumentIOException)1 IdLock (org.apache.hadoop.hbase.util.IdLock)1