You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2023/01/09 08:23:56 UTC

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

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


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ratis/RatisHelper.java:
##########
@@ -483,4 +488,81 @@ 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.
+   * If not isRandom, then use host to match the target leader.
+   * 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(RaftServer server,
+      RaftGroupId groupId, RaftPeerId targetPeerId)
+      throws IOException {
+    RaftGroup raftGroup = server.getDivision(groupId).getGroup();
+    RaftClient raftClient = createBackoffRaftClient(raftGroup);
+    if (!raftGroup.getPeers().stream().map(RaftPeer::getId)
+        .collect(Collectors.toSet()).contains(targetPeerId)) {
+      throw new IOException("Cannot choose the target leader. The expected " +
+          "leader RaftPeerId is " + targetPeerId + " and the peers are " +
+          raftGroup.getPeers().stream().map(RaftPeer::getId)
+              .collect(Collectors.toList()) + ".");
+    }
+    LOG.info("Chosen the targetLeaderId {} to transfer leadership",
+        targetPeerId);
+
+    // Set priority
+    List<RaftPeer> peersWithNewPriorities = new ArrayList<>();
+    for (RaftPeer peer : raftGroup.getPeers()) {
+      peersWithNewPriorities.add(
+          RaftPeer.newBuilder(peer)
+              .setPriority(peer.getId().equals(targetPeerId) ? 2 : 1)

Review Comment:
   Yes, the SetConfiguration request will sync and renew the conf between RaftPeers including the priorities.



-- 
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