liyuheng55555 commented on code in PR #12116:
URL: https://github.com/apache/iotdb/pull/12116#discussion_r1512345944


##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/RouteBalancer.java:
##########
@@ -127,10 +133,16 @@ public RouteBalancer(IManager configManager) {
   public synchronized Map<TConsensusGroupId, Pair<Integer, Integer>> 
balanceRegionLeader() {
     Map<TConsensusGroupId, Pair<Integer, Integer>> differentRegionLeaderMap =
         new ConcurrentHashMap<>();
-    if (IS_ENABLE_AUTO_LEADER_BALANCE_FOR_SCHEMA_REGION) {
+    if (IS_ENABLE_AUTO_LEADER_BALANCE_FOR_SCHEMA_REGION
+        && 
(!ConsensusFactory.RATIS_CONSENSUS.equals(SCHEMA_REGION_CONSENSUS_PROTOCOL_CLASS)
+            || System.currentTimeMillis() - 
lastFailedTimeForBalanceRatisSchemaLeader
+                > BALANCE_RATIS_LEADER_FAILED_INTERVAL)) {
       
differentRegionLeaderMap.putAll(balanceRegionLeader(TConsensusGroupType.SchemaRegion));
     }
-    if (IS_ENABLE_AUTO_LEADER_BALANCE_FOR_DATA_REGION) {
+    if (IS_ENABLE_AUTO_LEADER_BALANCE_FOR_DATA_REGION
+        && 
(!ConsensusFactory.RATIS_CONSENSUS.equals(DATA_REGION_CONSENSUS_PROTOCOL_CLASS)
+            || System.currentTimeMillis() - 
lastFailedTimeForBalanceRatisDataLeader
+                > BALANCE_RATIS_LEADER_FAILED_INTERVAL)) {

Review Comment:
   Those `if` check are somewhat annoying... Is it possible to optimize or 
simplify ?



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/RouteBalancer.java:
##########
@@ -199,6 +211,14 @@ private Map<TConsensusGroupId, Pair<Integer, Integer>> 
balanceRegionLeader(
                   
clientHandler.getRequest(i).getNewLeaderNode().getDataNodeId());
         } else {
           
differentRegionLeaderMap.remove(clientHandler.getRequest(i).getRegionId());
+          if (TConsensusGroupType.SchemaRegion.equals(regionGroupType)
+              && 
ConsensusFactory.RATIS_CONSENSUS.equals(SCHEMA_REGION_CONSENSUS_PROTOCOL_CLASS))
 {
+            lastFailedTimeForBalanceRatisSchemaLeader = 
System.currentTimeMillis();
+          }
+          if (TConsensusGroupType.DataRegion.equals(regionGroupType)
+              && 
ConsensusFactory.RATIS_CONSENSUS.equals(DATA_REGION_CONSENSUS_PROTOCOL_CLASS)) {
+            lastFailedTimeForBalanceRatisDataLeader = 
System.currentTimeMillis();
+          }

Review Comment:
   Here too



-- 
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: reviews-unsubscr...@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to