xichen01 commented on code in PR #5549:
URL: https://github.com/apache/ozone/pull/5549#discussion_r1389604520


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ratis/RatisHelper.java:
##########
@@ -545,6 +552,39 @@ null, raftGroup, createRetryPolicy(conf), tlsConfig, 
conf)) {
             targetPeerId, reply);
         throw new IOException(reply.getException());
       }
+    } finally {
+      // Raft peers priorities need to be reset regardless of the result
+      // of transfer leadership
+      resetPriorities(conf, raftGroup, tlsConfig);

Review Comment:
   Is it a good practice to execute `resetPriorities` in `finally`? If the 
leadership transfer fails but `resetPriorities` succeeds, could this lead to 
unexpected issues? maybe we can execute   `resetPriorities` only when the 
leadership transfer is successful."



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ratis/RatisHelper.java:
##########
@@ -545,6 +552,39 @@ null, raftGroup, createRetryPolicy(conf), tlsConfig, 
conf)) {
             targetPeerId, reply);
         throw new IOException(reply.getException());
       }
+    } finally {
+      // Raft peers priorities need to be reset regardless of the result
+      // of transfer leadership
+      resetPriorities(conf, raftGroup, tlsConfig);
+    }
+  }
+
+  private static void resetPriorities(ConfigurationSource conf,
+      RaftGroup raftGroup, GrpcTlsConfig tlsConfig) {
+    List<RaftPeer> resetPeers = new ArrayList<>();
+    for (RaftPeer peer : raftGroup.getPeers()) {
+      resetPeers.add(
+          RaftPeer.newBuilder(peer)
+              .setPriority(NEUTRAL_PRIORITY)
+              .build()
+      );
+    }
+    LOG.info("Resetting Raft peers priorities after transfer leadership");
+    try (RaftClient raftClient = newRaftClient(SupportedRpcType.GRPC, null,
+        null, raftGroup, createRetryPolicy(conf), tlsConfig, conf)) {
+      RaftClientReply reply = raftClient.admin().setConfiguration(resetPeers);
+      if (reply.isSuccess()) {
+        LOG.info("Successfully reset priorities for division: {}",
+            resetPeers);
+      } else {
+        LOG.warn("Failed to reset priorities for division: {}." +
+            " Ratis reply: {}", resetPeers, reply);
+      }
+    } catch (IOException e) {
+      LOG.error("Exception thrown when trying to reset priorities for " +

Review Comment:
   Is it necessary to prompt User that `resetPriorities` failed by command line 
output?



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