HBASE-19642 Fix locking for peer modification procedure

This commit is contained in:
zhangduo 2017-12-27 18:27:13 +08:00
parent ac07e07988
commit b40c426806
1 changed files with 18 additions and 3 deletions

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 {