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/13 00:25:36 UTC

[GitHub] [ozone] szetszwo commented on a diff in pull request #4265: HDDS-7687. Support OM transfer Ratis leadership

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


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ratis/RatisHelper.java:
##########
@@ -488,4 +490,62 @@ 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 division      the Raft division
+   * @param targetPeerId  the target expected leader
+   * @throws IOException
+   */
+  public static void transferRatisLeadership(ConfigurationSource conf,
+      RaftServer.Division division, RaftPeerId targetPeerId)

Review Comment:
   Pass `raftGroup` instead.



##########
hadoop-ozone/dist/src/main/smoketest/omha/testOMHA.robot:
##########
@@ -182,4 +194,38 @@ Restart OM and Verify Ratis Logs
     # Verify that the logs match with the Leader OMs logs
     List Should Contain Sub List    ${logsAfter}        ${logsLeader}
 
+Transfer Leadership for OM
+    # Check OM write operation before failover
+    Create volume and bucket
+    Write Test File
+
+    # Find Leader OM and one Follower OM
+    ${leaderOM} =           Get OM Leader Node
+                            LOG                     Leader OM: ${leaderOM}
+    ${followerOM} =         Get One OM Follower Node
+                            LOG                     Follower OM: ${followerOM}
+    # Transfer leadership to the Follower OM
+    ${result} =             Execute                 ozone admin om transfer --service-id=omservice -n ${followerOM}
+                            LOG                     ${result}
+                            Should Contain          ${result}               Transfer leadership successfully
+
+    ${newLeaderOM} =        Get OM Leader Node
+                            Should be Equal         ${followerOM}           ${newLeaderOM}
+    Write Test File
+
+Transfer Leadership for OM randomly
+    # Check OM write operation before failover
+    Create volume and bucket
+    Write Test File
 
+    # Find Leader OM and one Follower OM
+    ${leaderOM} =           Get OM Leader Node
+                            LOG                     Leader OM: ${leaderOM}
+    # Transfer leadership to the Follower OM
+    ${result} =             Execute                 ozone admin om transfer -r
+                            LOG                     ${result}
+                            Should Contain          ${result}               Transfer leadership successfully
+
+    ${newLeaderOM} =        Get OM Leader Node
+                            Should Not be Equal     ${leaderOM}             ${newLeaderOM}

Review Comment:
   Let add a test case with a specific new leader.  Just transfer it back to `${leaderOM}`.
   
   



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ratis/RatisHelper.java:
##########
@@ -488,4 +490,62 @@ 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 division      the Raft division
+   * @param targetPeerId  the target expected leader
+   * @throws IOException
+   */
+  public static void transferRatisLeadership(ConfigurationSource conf,
+      RaftServer.Division division, RaftPeerId targetPeerId)
+      throws IOException {
+    RaftGroup raftGroup = division.getGroup();
+    // TODO: need a common raft client related conf.
+    RaftClient raftClient = newRaftClient(SupportedRpcType.GRPC, null,

Review Comment:
   The `raftClient` is never closed.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java:
##########
@@ -3023,6 +3025,51 @@ public ServiceInfoEx getServiceInfo() throws IOException {
     return new ServiceInfoEx(getServiceList(), caCertPem, caCertPemList);
   }
 
+  @Override
+  public void transferLeadership(String nodeId)
+      throws IOException {
+    final UserGroupInformation ugi = getRemoteUser();
+    if (!isAdmin(ugi)) {
+      throw new OMException(
+          "Only Ozone admins are allowed to transfer raft leadership.",
+          PERMISSION_DENIED);
+    }
+    if (!isRatisEnabled) {
+      throw new IOException("OM HA not enabled..");
+    }
+    boolean auditSuccess = true;
+    Map<String, String> auditMap = new LinkedHashMap<>();
+    auditMap.put("nodeId", nodeId);
+    try {
+      RaftGroupId groupID = omRatisServer.getRaftGroup().getGroupId();
+      RaftServer.Division division = omRatisServer.getServer()
+          .getDivision(groupID);
+      RaftPeerId targetPeerId;
+      if (nodeId.isEmpty()) {
+        RaftPeer curLeader = omRatisServer.getLeader();
+        targetPeerId = division.getGroup()
+            .getPeers().stream().filter(a -> !a.equals(curLeader)).findFirst()
+            .map(RaftPeer::getId).orElse(null);

Review Comment:
   Use `orElseThrow`.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/om/TransferOmLeaderSubCommand.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.hadoop.ozone.admin.om;
+
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol;
+import picocli.CommandLine;
+import java.util.concurrent.Callable;
+
+
+/**
+ * Handler of ozone admin om transfer command.
+ */
+@CommandLine.Command(
+    name = "transfer",
+    description = "Manually transfer the raft leadership to the target node.",
+    mixinStandardHelpOptions = true,
+    versionProvider = HddsVersionProvider.class
+)
+public class TransferOmLeaderSubCommand implements Callable<Void> {
+
+  @CommandLine.ParentCommand
+  private OMAdmin parent;
+
+  @CommandLine.Option(
+      names = {"-id", "--service-id"},
+      description = "Ozone Manager Service ID."
+  )
+  private String omServiceId;
+
+  @CommandLine.ArgGroup(multiplicity = "1")
+  private TransferOption configGroup;
+
+  static class TransferOption {
+    @CommandLine.Option(
+        names = {"-n", "--nodeId"},

Review Comment:
   Use `transfereeId` or `newLeaderId`.
   
   BTW, is there a way to specify the which OM to send the command?



##########
hadoop-hdds/interface-client/src/main/proto/hdds.proto:
##########
@@ -452,3 +452,10 @@ message ContainerBalancerConfigurationProto {
     required bool shouldRun = 18;
     optional int32 nextIterationIndex = 19;
 }
+
+message TransferLeadershipRequestProto {
+    required string nodeId = 1;

Review Comment:
   Let's rename it to `transfereeId` or `newLeaderId`.



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