Search in sources :

Example 51 with Procedure

use of org.apache.hadoop.hbase.procedure2.Procedure 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 52 with Procedure

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

the class ProcedureTestingUtility method submitAndWait.

public static <TEnv> long submitAndWait(Configuration conf, TEnv env, Procedure<TEnv> proc) throws IOException {
    NoopProcedureStore procStore = new NoopProcedureStore();
    ProcedureExecutor<TEnv> procExecutor = new ProcedureExecutor<>(conf, env, procStore);
    procStore.start(1);
    procExecutor.start(1, false);
    try {
        return submitAndWait(procExecutor, proc, HConstants.NO_NONCE, HConstants.NO_NONCE);
    } finally {
        procStore.stop(false);
        procExecutor.stop();
    }
}
Also used : NoopProcedureStore(org.apache.hadoop.hbase.procedure2.store.NoopProcedureStore)

Aggregations

Procedure (org.apache.hadoop.hbase.procedure2.Procedure)29 TestProcedure (org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure)26 Test (org.junit.Test)26 TableName (org.apache.hadoop.hbase.TableName)16 IOException (java.io.IOException)10 LockAndQueue (org.apache.hadoop.hbase.procedure2.LockAndQueue)10 ProcedureInfo (org.apache.hadoop.hbase.ProcedureInfo)6 SequentialProcedure (org.apache.hadoop.hbase.procedure2.SequentialProcedure)5 ByteSlot (org.apache.hadoop.hbase.procedure2.util.ByteSlot)5 FileStatus (org.apache.hadoop.fs.FileStatus)4 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)4 LockProcedure (org.apache.hadoop.hbase.master.locking.LockProcedure)4 LoadCounter (org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter)4 ProcedureStore (org.apache.hadoop.hbase.procedure2.store.ProcedureStore)4 ProcedureIterator (org.apache.hadoop.hbase.procedure2.store.ProcedureStore.ProcedureIterator)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 MasterProcedureEnv (org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv)2 After (org.junit.After)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1