jackjlli commented on code in PR #8483:
URL: https://github.com/apache/pinot/pull/8483#discussion_r856594342


##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/assignment/instance/InstanceReplicaGroupPartitionSelector.java:
##########
@@ -180,14 +266,110 @@ public void selectInstances(Map<Integer, 
List<InstanceConfig>> poolToInstanceCon
         numInstancesToSelect = numInstanceConfigs;
       }
 
-      List<String> instancesToSelect = new ArrayList<>(numInstancesToSelect);
-      for (int i = 0; i < numInstancesToSelect; i++) {
-        instancesToSelect.add(instanceConfigs.get(i).getInstanceName());
+      List<String> instancesToSelect;
+      if (_replicaGroupPartitionConfig.isMinimizeDataMovement() && 
_existingInstancePartitions != null) {
+        // Minimize data movement.
+        List<String> existingInstances = 
_existingInstancePartitions.getInstances(0, 0);
+        Set<String> candidateInstances = new LinkedHashSet<>();
+        instanceConfigs.forEach(k -> 
candidateInstances.add(k.getInstanceName()));
+        instancesToSelect =
+            getInstancesWithMinimumMovement(numInstancesToSelect, 
candidateInstances, existingInstances);
+      } else {
+        // Select instances sequentially.
+        instancesToSelect = new ArrayList<>(numInstancesToSelect);
+        for (int i = 0; i < numInstancesToSelect; i++) {
+          instancesToSelect.add(instanceConfigs.get(i).getInstanceName());
+        }
       }
       instancesToSelect.sort(null);
       LOGGER.info("Selecting instances: {} for table: {}", instancesToSelect, 
_tableNameWithType);
       // Set the instances as partition 0 replica 0
       instancePartitions.setInstances(0, 0, instancesToSelect);
     }
   }
+
+  /**
+   * Select instances with minimum movement.
+   * This algorithm can solve the following scenarios:

Review Comment:
   TODO comments added.



-- 
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: commits-unsubscr...@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to