From b40c42680656fd37a15936bdee1abfdb380c0ff5 Mon Sep 17 00:00:00 2001 From: zhangduo Date: Wed, 27 Dec 2017 18:27:13 +0800 Subject: [PATCH] HBASE-19642 Fix locking for peer modification procedure --- .../replication/ModifyPeerProcedure.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/ModifyPeerProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/ModifyPeerProcedure.java index 279fbc78753..a682606bad1 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/ModifyPeerProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/ModifyPeerProcedure.java @@ -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 {