J-HowHuang commented on code in PR #15891:
URL: https://github.com/apache/pinot/pull/15891#discussion_r2138512198


##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/rebalance/tenant/DefaultTenantRebalancer.java:
##########
@@ -49,6 +56,80 @@ public DefaultTenantRebalancer(PinotHelixResourceManager 
pinotHelixResourceManag
 
   @Override
   public TenantRebalanceResult rebalance(TenantRebalanceConfig config) {
+    Map<String, RebalanceResult> dryRunResults = new HashMap<>();
+    Set<String> tables = getTenantTables(config.getTenantName());
+    Set<String> allowTables = config.getAllowTables();
+    if (!allowTables.isEmpty()) {
+      tables.retainAll(allowTables);
+    }
+    tables.removeAll(config.getBlockTables());
+    tables.forEach(table -> {
+      try {
+        RebalanceConfig rebalanceConfig = RebalanceConfig.copy(config);
+        rebalanceConfig.setDryRun(true);
+        dryRunResults.put(table,
+            _pinotHelixResourceManager.rebalanceTable(table, rebalanceConfig, 
createUniqueRebalanceJobIdentifier(),
+                false));
+      } catch (TableNotFoundException exception) {
+        dryRunResults.put(table, new RebalanceResult(null, 
RebalanceResult.Status.FAILED, exception.getMessage(),
+            null, null, null, null, null));
+      }
+    });
+    if (config.isDryRun()) {
+      return new TenantRebalanceResult(null, dryRunResults, 
config.isVerboseResult());
+    }
+
+    String tenantRebalanceJobId = createUniqueRebalanceJobIdentifier();
+    TenantRebalanceObserver observer = new 
ZkBasedTenantRebalanceObserver(tenantRebalanceJobId, config.getTenantName(),
+        tables, _pinotHelixResourceManager);
+    observer.onTrigger(TenantRebalanceObserver.Trigger.START_TRIGGER, null, 
null);
+    ConcurrentLinkedQueue<String> parallelQueue = createTableQueue(config, 
dryRunResults);
+    // ensure atleast 1 thread is created to run the sequential table 
rebalance operations
+    int parallelism = Math.max(config.getDegreeOfParallelism(), 1);
+    try {
+      for (int i = 0; i < parallelism; i++) {
+        _executorService.submit(() -> {
+          while (true) {
+            String table = parallelQueue.poll();
+            if (table == null) {
+              break;
+            }
+            RebalanceConfig rebalanceConfig = RebalanceConfig.copy(config);
+            rebalanceConfig.setDryRun(false);
+            if (dryRunResults.get(table)
+                .getRebalanceSummaryResult()
+                .getSegmentInfo()
+                .getReplicationFactor()
+                .getExpectedValueAfterRebalance() == 1) {
+              rebalanceConfig.setMinAvailableReplicas(0);

Review Comment:
   You're right, this is one concern we should deal with. I'm planning to make 
a separate PR for this.



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