You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "szetszwo (via GitHub)" <gi...@apache.org> on 2023/02/08 17:47:26 UTC

[GitHub] [ozone] szetszwo commented on a diff in pull request #4128: HDDS-5686. Support transfer leadership

szetszwo commented on code in PR #4128:
URL: https://github.com/apache/ozone/pull/4128#discussion_r1100477895


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMClientProtocolServer.java:
##########
@@ -783,6 +796,71 @@ public ScmInfo getScmInfo() throws IOException {
     }
   }
 
+  @Override
+  public void transferLeadership(String nodeId)
+      throws IOException {
+    getScm().checkAdminAccess(getRemoteUser());
+    boolean auditSuccess = true;
+    final Map<String, String> auditMap = Maps.newHashMap();
+    auditMap.put("nodeId", nodeId);
+    try {
+      SCMRatisServer scmRatisServer = scm.getScmHAManager().getRatisServer();

Review Comment:
   Check if HA is enabled.



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ratis/RatisHelper.java:
##########
@@ -488,4 +490,64 @@ public static void debug(ByteBuf buf, String name, Logger log) {
     }
     log.debug("{}: {}\n  {}", name, buf, builder);
   }
+
+
+  /**
+   * Use raft client to send admin request, transfer the leadership.
+   * 1. Set priority and send setConfiguration request
+   * 2. Trigger transferLeadership API.
+   *
+   * @param server        the Raft server
+   * @param groupId       the Raft group Id
+   * @param targetPeerId  the target expected leader
+   * @throws IOException
+   */
+  public static void transferRatisLeadership(ConfigurationSource conf,
+      RaftServer server, RaftGroupId groupId, RaftPeerId targetPeerId)
+      throws IOException {
+    RaftGroup raftGroup = server.getDivision(groupId).getGroup();
+    // TODO: use common raft client related conf
+    RaftClient raftClient = newRaftClient(SupportedRpcType.GRPC, null,
+        null, raftGroup, createRetryPolicy(conf), null, conf);
+    if (!raftGroup.getPeers().stream().map(RaftPeer::getId)
+        .collect(Collectors.toSet()).contains(targetPeerId)) {

Review Comment:
   Use ` if (raftGroup.getPeer(targetPeerId) == null)`.



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMClientProtocolServer.java:
##########
@@ -783,6 +796,71 @@ public ScmInfo getScmInfo() throws IOException {
     }
   }
 
+  @Override
+  public void transferLeadership(String nodeId)
+      throws IOException {
+    getScm().checkAdminAccess(getRemoteUser());
+    boolean auditSuccess = true;
+    final Map<String, String> auditMap = Maps.newHashMap();
+    auditMap.put("nodeId", nodeId);
+    try {
+      SCMRatisServer scmRatisServer = scm.getScmHAManager().getRatisServer();
+      RaftServer server = scmRatisServer.getDivision().getRaftServer();

Review Comment:
   Don't get `RaftServer`.  It only needs a division.



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ratis/RatisHelper.java:
##########
@@ -488,4 +490,64 @@ public static void debug(ByteBuf buf, String name, Logger log) {
     }
     log.debug("{}: {}\n  {}", name, buf, builder);
   }
+
+
+  /**
+   * Use raft client to send admin request, transfer the leadership.
+   * 1. Set priority and send setConfiguration request
+   * 2. Trigger transferLeadership API.
+   *
+   * @param server        the Raft server
+   * @param groupId       the Raft group Id
+   * @param targetPeerId  the target expected leader
+   * @throws IOException
+   */
+  public static void transferRatisLeadership(ConfigurationSource conf,
+      RaftServer server, RaftGroupId groupId, RaftPeerId targetPeerId)

Review Comment:
   Pass a division instead of a 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-unsubscribe@ozone.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org