HBASE-19642 Fix locking for peer modification procedure

This commit is contained in:
zhangduo 2017-12-27 18:27:13 +08:00
parent fdc907140b
commit 5fc90244a8
2 changed files with 32 additions and 3 deletions

View File

@ -610,6 +610,20 @@ public class MasterProcedureScheduler extends AbstractProcedureScheduler {
public boolean requireExclusiveLock(Procedure proc) {
return requirePeerExclusiveLock((PeerProcedureInterface) proc);
}
@Override
public boolean isAvailable() {
if (isEmpty()) {
return false;
}
if (getLockStatus().hasExclusiveLock()) {
// if we have an exclusive lock already taken
// only child of the lock owner can be executed
Procedure nextProc = peek();
return nextProc != null && getLockStatus().hasLockAccess(nextProc);
}
return true;
}
}
// ============================================================================

View File

@ -46,6 +46,8 @@ public abstract class ModifyPeerProcedure
protected String peerId;
private volatile boolean locked;
// used to keep compatible with old client where we can only returns after updateStorage.
protected ProcedurePrepareLatch latch;
@ -145,16 +147,29 @@ public abstract class ModifyPeerProcedure
@Override
protected LockState acquireLock(MasterProcedureEnv env) {
return env.getProcedureScheduler().waitPeerExclusiveLock(this, peerId)
? LockState.LOCK_EVENT_WAIT
: LockState.LOCK_ACQUIRED;
if (env.getProcedureScheduler().waitPeerExclusiveLock(this, peerId)) {
return LockState.LOCK_EVENT_WAIT;
}
locked = true;
return LockState.LOCK_ACQUIRED;
}
@Override
protected void releaseLock(MasterProcedureEnv env) {
locked = false;
env.getProcedureScheduler().wakePeerExclusiveLock(this, peerId);
}
@Override
protected boolean holdLock(MasterProcedureEnv env) {
return true;
}
@Override
protected boolean hasLock(MasterProcedureEnv env) {
return locked;
}
@Override
protected void rollbackState(MasterProcedureEnv env, PeerModificationState state)
throws IOException, InterruptedException {