HBASE-19936 Introduce a new base class for replication peer procedure

Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/1c4938da
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/1c4938da
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/1c4938da

Branch: refs/heads/HBASE-19397-branch-2
Commit: 1c4938dab8730eb596ecfa0ab414334887fd14a4
Parents: 0502464
Author: zhangduo <zhang...@apache.org>
Authored: Mon Feb 5 16:14:25 2018 +0800
Committer: zhangduo <zhang...@apache.org>
Committed: Mon Feb 26 15:58:44 2018 +0800

----------------------------------------------------------------------
 .../src/main/protobuf/MasterProcedure.proto     |  2 +-
 .../replication/AbstractPeerProcedure.java      | 97 ++++++++++++++++++++
 .../master/replication/ModifyPeerProcedure.java | 67 +-------------
 3 files changed, 102 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/1c4938da/hbase-protocol-shaded/src/main/protobuf/MasterProcedure.proto
----------------------------------------------------------------------
diff --git a/hbase-protocol-shaded/src/main/protobuf/MasterProcedure.proto 
b/hbase-protocol-shaded/src/main/protobuf/MasterProcedure.proto
index e45e12f..726217f 100644
--- a/hbase-protocol-shaded/src/main/protobuf/MasterProcedure.proto
+++ b/hbase-protocol-shaded/src/main/protobuf/MasterProcedure.proto
@@ -399,7 +399,7 @@ message RefreshPeerParameter {
   required ServerName target_server = 3;
 }
 
-message ModifyPeerStateData {
+message PeerProcedureStateData {
   required string peer_id = 1;
 }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/1c4938da/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/AbstractPeerProcedure.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/AbstractPeerProcedure.java
 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/AbstractPeerProcedure.java
new file mode 100644
index 0000000..0ad8a63
--- /dev/null
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/AbstractPeerProcedure.java
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.master.replication;
+
+import java.io.IOException;
+import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
+import org.apache.hadoop.hbase.master.procedure.PeerProcedureInterface;
+import org.apache.hadoop.hbase.master.procedure.ProcedurePrepareLatch;
+import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer;
+import org.apache.hadoop.hbase.procedure2.StateMachineProcedure;
+import org.apache.yetus.audience.InterfaceAudience;
+
+import 
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.PeerProcedureStateData;
+
+/**
+ * The base class for all replication peer related procedure.
+ */
+@InterfaceAudience.Private
+public abstract class AbstractPeerProcedure<TState>
+    extends StateMachineProcedure<MasterProcedureEnv, TState> implements 
PeerProcedureInterface {
+
+  protected String peerId;
+
+  private volatile boolean locked;
+
+  // used to keep compatible with old client where we can only returns after 
updateStorage.
+  protected ProcedurePrepareLatch latch;
+
+  protected AbstractPeerProcedure() {
+  }
+
+  protected AbstractPeerProcedure(String peerId) {
+    this.peerId = peerId;
+    this.latch = ProcedurePrepareLatch.createLatch(2, 0);
+  }
+
+  public ProcedurePrepareLatch getLatch() {
+    return latch;
+  }
+
+  @Override
+  public String getPeerId() {
+    return peerId;
+  }
+
+  @Override
+  protected LockState acquireLock(MasterProcedureEnv env) {
+    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 serializeStateData(ProcedureStateSerializer serializer) 
throws IOException {
+    super.serializeStateData(serializer);
+    
serializer.serialize(PeerProcedureStateData.newBuilder().setPeerId(peerId).build());
+  }
+
+  @Override
+  protected void deserializeStateData(ProcedureStateSerializer serializer) 
throws IOException {
+    super.deserializeStateData(serializer);
+    peerId = serializer.deserialize(PeerProcedureStateData.class).getPeerId();
+  }
+}

http://git-wip-us.apache.org/repos/asf/hbase/blob/1c4938da/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/ModifyPeerProcedure.java
----------------------------------------------------------------------
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 c225619..83c5134 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
@@ -19,52 +19,30 @@ package org.apache.hadoop.hbase.master.replication;
 
 import java.io.IOException;
 import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
-import org.apache.hadoop.hbase.master.procedure.PeerProcedureInterface;
 import org.apache.hadoop.hbase.master.procedure.ProcedurePrepareLatch;
-import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer;
 import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException;
 import org.apache.hadoop.hbase.procedure2.ProcedureYieldException;
-import org.apache.hadoop.hbase.procedure2.StateMachineProcedure;
 import org.apache.hadoop.hbase.replication.ReplicationException;
 import org.apache.yetus.audience.InterfaceAudience;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import 
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.ModifyPeerStateData;
 import 
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.PeerModificationState;
 
 /**
- * The base class for all replication peer related procedure.
+ * The base class for all replication peer related procedure except sync 
replication state
+ * transition.
  */
 @InterfaceAudience.Private
-public abstract class ModifyPeerProcedure
-    extends StateMachineProcedure<MasterProcedureEnv, PeerModificationState>
-    implements PeerProcedureInterface {
+public abstract class ModifyPeerProcedure extends 
AbstractPeerProcedure<PeerModificationState> {
 
   private static final Logger LOG = 
LoggerFactory.getLogger(ModifyPeerProcedure.class);
 
-  protected String peerId;
-
-  private volatile boolean locked;
-
-  // used to keep compatible with old client where we can only returns after 
updateStorage.
-  protected ProcedurePrepareLatch latch;
-
   protected ModifyPeerProcedure() {
   }
 
   protected ModifyPeerProcedure(String peerId) {
-    this.peerId = peerId;
-    this.latch = ProcedurePrepareLatch.createLatch(2, 0);
-  }
-
-  public ProcedurePrepareLatch getLatch() {
-    return latch;
-  }
-
-  @Override
-  public String getPeerId() {
-    return peerId;
+    super(peerId);
   }
 
   /**
@@ -150,31 +128,6 @@ public abstract class ModifyPeerProcedure
   }
 
   @Override
-  protected LockState acquireLock(MasterProcedureEnv env) {
-    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 {
     if (state == PeerModificationState.PRE_PEER_MODIFICATION) {
@@ -199,16 +152,4 @@ public abstract class ModifyPeerProcedure
   protected PeerModificationState getInitialState() {
     return PeerModificationState.PRE_PEER_MODIFICATION;
   }
-
-  @Override
-  protected void serializeStateData(ProcedureStateSerializer serializer) 
throws IOException {
-    super.serializeStateData(serializer);
-    
serializer.serialize(ModifyPeerStateData.newBuilder().setPeerId(peerId).build());
-  }
-
-  @Override
-  protected void deserializeStateData(ProcedureStateSerializer serializer) 
throws IOException {
-    super.deserializeStateData(serializer);
-    peerId = serializer.deserialize(ModifyPeerStateData.class).getPeerId();
-  }
 }

Reply via email to