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


##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/audit/OMAction.java:
##########
@@ -60,6 +60,7 @@ public enum OMAction implements AuditAction {
   RENEW_DELEGATION_TOKEN,
   CANCEL_DELEGATION_TOKEN,
   GET_SERVICE_LIST,
+  TRANSFER_LEADERSHIP,

Review Comment:
   I would suggest making transfer leadership action consistent in OMAction and 
SCMAction. The current naming is:
   
   - OMAction.TRANSFER_LEADERSIP
   - SCMAction.TRANSFER_SCM_LEADER



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java:
##########
@@ -776,4 +790,90 @@ public static 
ContainerProtos.ContainerCommandResponseProto processForDebug(
 
     return msg;
   }
+
+  /**
+   * 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 host          the string of the host, should be IP:PORT format
+   * @param isRandom      whether to choose random follower as target leader
+   * @param curLeader     the current Raft leader
+   * @throws IOException
+   */
+  public static void transferRatisLeadership(RaftServer server,

Review Comment:
   I think extracting these methods in LeadershipManager class would be more 
useful than keeping them in a util class.



##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/OzoneManagerProtocolClientSideTranslatorPB.java:
##########
@@ -1461,6 +1462,30 @@ public ServiceInfoEx getServiceInfo() throws IOException 
{
         resp.getCaCertificate(), resp.getCaCertsList());
   }
 
+  @Override
+  public void transferLeadership(String host, boolean isRandom)
+      throws IOException {
+    TransferOmLeadershipRequest.Builder builder = TransferOmLeadershipRequest.
+        newBuilder();
+    if (isRandom) {
+      builder.setIsRandom(true);
+    } else {
+      String pattern = "^((2((5[0-5])|([0-4]\\d)))|([0-1]?\\d{1,2}))(\\." +
+          "((2((5[0-5])|([0-4]\\d)))|([0-1]?\\d{1,2}))){3}:\\d+$";
+      if (host == null || !host.matches(pattern)) {
+        throw new IllegalArgumentException("Host is " + host + " or does not " 
+

Review Comment:
   This piece of code is duplicated in SCM and OM.  I think it makes sense to 
extract it in a shared class



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

Reply via email to