HBASE-20975 Lock may not be taken or released while rolling back procedure

This commit is contained in:
Allan Yang 2018-08-13 20:18:02 +08:00
parent bee8566f2c
commit ef02ab2372
1 changed files with 4 additions and 12 deletions

View File

@ -1363,29 +1363,21 @@ public class ProcedureExecutor<TEnvironment> {
assert subprocStack != null : "Called rollback with no steps executed rootProc=" + rootProc; assert subprocStack != null : "Called rollback with no steps executed rootProc=" + rootProc;
int stackTail = subprocStack.size(); int stackTail = subprocStack.size();
boolean reuseLock = false; while (stackTail-- > 0) {
while (stackTail --> 0) {
Procedure<TEnvironment> proc = subprocStack.get(stackTail); Procedure<TEnvironment> proc = subprocStack.get(stackTail);
LockState lockState; LockState lockState = acquireLock(proc);
if (!reuseLock && (lockState = acquireLock(proc)) != LockState.LOCK_ACQUIRED) { if (lockState != LockState.LOCK_ACQUIRED) {
// can't take a lock on the procedure, add the root-proc back on the // can't take a lock on the procedure, add the root-proc back on the
// queue waiting for the lock availability // queue waiting for the lock availability
return lockState; return lockState;
} }
lockState = executeRollback(proc); lockState = executeRollback(proc);
releaseLock(proc, false);
boolean abortRollback = lockState != LockState.LOCK_ACQUIRED; boolean abortRollback = lockState != LockState.LOCK_ACQUIRED;
abortRollback |= !isRunning() || !store.isRunning(); 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 && proc.hasLock()) {
releaseLock(proc, false);
}
// allows to kill the executor before something is stored to the wal. // allows to kill the executor before something is stored to the wal.
// useful to test the procedure recovery. // useful to test the procedure recovery.
if (abortRollback) { if (abortRollback) {