Apache9 commented on a change in pull request #3430:
URL: https://github.com/apache/hbase/pull/3430#discussion_r660286508



##########
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/ClaimReplicationQueuesProcedure.java
##########
@@ -0,0 +1,140 @@
+/**
+ * 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 java.util.Collections;
+import java.util.List;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
+import org.apache.hadoop.hbase.master.procedure.ServerProcedureInterface;
+import org.apache.hadoop.hbase.procedure2.Procedure;
+import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer;
+import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException;
+import org.apache.hadoop.hbase.procedure2.ProcedureUtil;
+import org.apache.hadoop.hbase.procedure2.ProcedureYieldException;
+import org.apache.hadoop.hbase.replication.ReplicationException;
+import org.apache.hadoop.hbase.replication.ReplicationQueueStorage;
+import org.apache.hadoop.hbase.util.RetryCounter;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
+import 
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.ClaimReplicationQueuesStateData;
+import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos;
+
+/**
+ * Used to assign the replication queues of a dead server to other region 
servers.
+ */
+@InterfaceAudience.Private
+public class ClaimReplicationQueuesProcedure extends 
Procedure<MasterProcedureEnv>
+  implements ServerProcedureInterface {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ClaimReplicationQueuesProcedure.class);
+
+  private ServerName crashedServer;
+
+  private RetryCounter retryCounter;
+
+  public ClaimReplicationQueuesProcedure() {
+  }
+
+  public ClaimReplicationQueuesProcedure(ServerName crashedServer) {
+    this.crashedServer = crashedServer;
+  }
+
+  @Override
+  public ServerName getServerName() {
+    return crashedServer;
+  }
+
+  @Override
+  public boolean hasMetaTableRegion() {
+    return false;
+  }
+
+  @Override
+  public ServerOperationType getServerOperationType() {
+    return ServerOperationType.CLAIM_REPLICATION_QUEUES;
+  }
+
+  @Override
+  protected Procedure<MasterProcedureEnv>[] execute(MasterProcedureEnv env)
+    throws ProcedureYieldException, ProcedureSuspendedException, 
InterruptedException {
+    ReplicationQueueStorage storage = 
env.getReplicationPeerManager().getQueueStorage();
+    try {
+      List<String> queues = storage.getAllQueues(crashedServer);
+      if (queues.isEmpty()) {
+        LOG.debug("Finish claiming replication queues for {}", crashedServer);
+        storage.removeReplicatorIfQueueIsEmpty(crashedServer);
+        // we are done
+        return null;
+      }
+      LOG.debug("There are {} replication queues need to be claimed for {}", 
queues.size(),
+        crashedServer);
+      List<ServerName> targetServers =
+        env.getMasterServices().getServerManager().getOnlineServersList();
+      if (targetServers.isEmpty()) {
+        throw new ReplicationException("no region server available");
+      }
+      Collections.shuffle(targetServers);
+      ClaimReplicationQueueRemoteProcedure[] procs =
+        new ClaimReplicationQueueRemoteProcedure[Math.min(queues.size(), 
targetServers.size())];
+      for (int i = 0; i < procs.length; i++) {
+        procs[i] = new ClaimReplicationQueueRemoteProcedure(crashedServer, 
queues.get(i),

Review comment:
       It will be scheduled next time. The exit condition is there is no 
replication queue for the given dead region server.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@hbase.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to