You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/08/04 01:49:10 UTC

[GitHub] [iotdb] neuyilan commented on a diff in pull request #6880: [IOTDB-4029] Latent routing policy for MultiLeader protocol

neuyilan commented on code in PR #6880:
URL: https://github.com/apache/iotdb/pull/6880#discussion_r937276001


##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/RouteBalancer.java:
##########
@@ -41,22 +45,64 @@ public class RouteBalancer {
 
   private final IManager configManager;
 
+  private final LazyRandomRouter lazyRandomRouter;
+
   public RouteBalancer(IManager configManager) {
     this.configManager = configManager;
+    this.lazyRandomRouter = new LazyRandomRouter();
   }
 
   public Map<TConsensusGroupId, TRegionReplicaSet> genLatestRegionRouteMap(
       List<TRegionReplicaSet> regionReplicaSets) {
-    return genRouter().genLatestRegionRouteMap(regionReplicaSets);
+    List<TRegionReplicaSet> schemaRegionGroups = new ArrayList<>();
+    List<TRegionReplicaSet> dataRegionGroups = new ArrayList<>();
+
+    regionReplicaSets.forEach(
+        regionReplicaSet -> {
+          switch (regionReplicaSet.getRegionId().getType()) {
+            case SchemaRegion:
+              schemaRegionGroups.add(regionReplicaSet);
+              break;
+            case DataRegion:
+              dataRegionGroups.add(regionReplicaSet);
+              break;
+          }
+        });
+
+    // Generate SchemaRegionRouteMap
+    Map<TConsensusGroupId, TRegionReplicaSet> result =
+        genRouter(TConsensusGroupType.SchemaRegion).genLatestRegionRouteMap(schemaRegionGroups);
+    // Generate DataRegionRouteMap
+    result.putAll(
+        genRouter(TConsensusGroupType.DataRegion).genLatestRegionRouteMap(dataRegionGroups));
+    return result;
   }
 
-  private IRouter genRouter() {
+  private IRouter genRouter(TConsensusGroupType groupType) {
     String policy = ConfigNodeDescriptor.getInstance().getConf().getRoutingPolicy();
-    if (policy.equals(leaderPolicy)) {
-      return new LeaderRouter(
-          getLoadManager().getAllLeadership(), getLoadManager().getAllLoadScores());
-    } else {
-      return new LoadScoreGreedyRouter(getLoadManager().getAllLoadScores());
+    switch (groupType) {
+      case SchemaRegion:
+        if (policy.equals(leaderPolicy)) {
+          return new LeaderRouter(
+              getLoadManager().getAllLeadership(), getLoadManager().getAllLoadScores());
+        } else {
+          return new LoadScoreGreedyRouter(getLoadManager().getAllLoadScores());
+        }
+      case DataRegion:
+      default:
+        if (ConfigNodeDescriptor.getInstance()
+            .getConf()
+            .getDataRegionConsensusProtocolClass()
+            .equals(ConsensusFactory.MultiLeaderConsensus)) {
+          // Latent router for MultiLeader consensus protocol
+          lazyRandomRouter.updateUnknownDataNodes(getLoadManager().getUnknownDataNodes(-1));

Review Comment:
   Why not initialize a globally unique variable like `lazyRandomRouter`?
   I think this method may be called frequently, so many objects will be created and GC by the jvm



-- 
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-unsubscribe@iotdb.apache.org

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