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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]