Xushaohong commented on code in PR #4276:
URL: https://github.com/apache/ozone/pull/4276#discussion_r1108057576
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMClientProtocolServer.java:
##########
@@ -782,6 +795,89 @@ public ScmInfo getScmInfo() throws IOException {
}
}
+ @Override
+ public void transferLeadership(String newLeaderId)
+ throws IOException {
+ getScm().checkAdminAccess(getRemoteUser());
+ if (!SCMHAUtils.isSCMHAEnabled(getScm().getConfiguration())) {
+ throw new SCMException("SCM HA not enabled.",
ResultCodes.INTERNAL_ERROR);
+ }
+ boolean auditSuccess = true;
+ final Map<String, String> auditMap = Maps.newHashMap();
+ auditMap.put("newLeaderId", newLeaderId);
+ try {
+ SCMRatisServer scmRatisServer = scm.getScmHAManager().getRatisServer();
+ RaftGroup group = scmRatisServer.getDivision().getGroup();
+ RaftPeerId targetPeerId;
+ if (newLeaderId.isEmpty()) {
+ RaftPeer curLeader = ((SCMRatisServerImpl) scm.getScmHAManager()
+ .getRatisServer()).getLeader();
+ targetPeerId = group.getPeers()
+ .stream()
+ .filter(a -> !a.equals(curLeader)).findFirst()
+ .map(RaftPeer::getId)
+ .orElseThrow(() -> new IOException("Cannot" +
+ " find a new leader to transfer leadership."));
+ } else {
+ String ratisAddr = convertToRatisAddr(newLeaderId);
Review Comment:
> What is the problem of using UUID? Too long?
Hi @szetszwo.
OM uses the OmNodeId in the conf as the **RaftPeerId**, so we can directly
find the new leader in the Raft group info by the passed nodeId.
SCM uses the UUID as the **RaftPeerId**, we have no way to know the new
leader's UUID, so I added the conversion from ScmNodeId to RatisAddress and
then got the **RaftPeerId**.
--
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]