NealSun96 commented on code in PR #2189:
URL: https://github.com/apache/helix/pull/2189#discussion_r941634942


##########
helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/WagedRebalancer.java:
##########
@@ -562,6 +590,57 @@ private Map<String, ResourceAssignment> partialRebalance(
     }
     _partialRebalanceLatency.endMeasuringLatency();
     LOG.info("Finish calculating the new best possible assignment.");
+
+    if (isBestPossibleChanged) {
+      LOG.info("Schedule a new rebalance after the new best possible 
calculation has finished.");
+      RebalanceUtil.scheduleOnDemandPipeline(clusterData.getClusterName(), 0L, 
false);
+    }
+  }
+
+  private Map<String, ResourceAssignment> emergencyRebalance(
+      ResourceControllerDataProvider clusterData, Map<String, Resource> 
resourceMap,
+      Set<String> activeNodes, final CurrentStateOutput currentStateOutput,
+      RebalanceAlgorithm algorithm)
+      throws HelixRebalanceException {
+    Map<String, ResourceAssignment> currentBestPossibleAssignment =
+        getBestPossibleAssignment(_assignmentMetadataStore, currentStateOutput,
+            resourceMap.keySet());
+    ClusterModel clusterModel;
+    try {
+      clusterModel = ClusterModelProvider
+          .generateClusterModelForEmergencyRebalance(clusterData, resourceMap, 
activeNodes,
+              currentBestPossibleAssignment);
+    } catch (Exception ex) {
+      throw new HelixRebalanceException("Failed to generate cluster model for 
emergency rebalance.",
+          HelixRebalanceException.Type.INVALID_CLUSTER_STATUS, ex);
+    }
+
+    // Only calculate if there are illegal placements, meaning the cluster 
model is non null;
+    // otherwise, start partial rebalance and return the current best possible.
+    if (clusterModel == null) {
+      // Perform partial rebalance for a new best possible assignment
+      partialRebalance(clusterData, resourceMap, activeNodes, 
currentStateOutput, algorithm);
+      return currentBestPossibleAssignment;
+    }
+
+    _asyncPartialRebalanceResult.cancel(true);

Review Comment:
   @qqu0127 Good point. Will add that for better visibility. 
   @desaikomal Attempting to cancel here because there have been illegal 
placements, therefore the previous calculation can no longer be applied. This 
cancel operation is to cut down unnecessary work. 



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