himanshukandwal commented on code in PR #2778:
URL: https://github.com/apache/helix/pull/2778#discussion_r1525546851


##########
helix-core/src/main/java/org/apache/helix/controller/rebalancer/MaintenanceRebalancer.java:
##########
@@ -55,12 +59,19 @@ public IdealState computeNewIdealState(String resourceName, 
IdealState currentId
 
     // One principal is to prohibit DROP -> OFFLINE and OFFLINE -> DROP state 
transitions.
     // Derived preference list from current state with state priority
+    StateModelDefinition stateModelDef = 
clusterData.getStateModelDef(currentIdealState.getStateModelDefRef());
+
     for (Partition partition : currentStateMap.keySet()) {
       Map<String, String> stateMap = currentStateMap.get(partition);
       List<String> preferenceList = new ArrayList<>(stateMap.keySet());
+
+      // This sorting preserves the ordering of current state hosts in the 
order of current IS pref list
       Collections.sort(preferenceList, new 
PreferenceListNodeComparator(stateMap,
-          
clusterData.getStateModelDef(currentIdealState.getStateModelDefRef()),
-          Collections.<String>emptyList()));
+          stateModelDef, 
currentIdealState.getPreferenceList(partition.getPartitionName())));
+
+      // This sorts the current state hosts based on the priority
+      preferenceList.sort(new StatePriorityComparator(stateMap, 
stateModelDef));

Review Comment:
   So this is getting applied when we have already sorted the current state 
hosts in the preference-list order. (line: 70)
   ```
   pref-list: [A, B, C]
   current-state: {
       A: FOLLOWER,
       B: LEADER,
       C: FOLLOWER
   }
   ```
   Lets say `newPrefList = new ArrayList<>(current-state.keySet())` => `[C, B, 
A]`
   ```
   Sort 1: Sort based on preference-list order:
   newPrefList = [C, B, A] => [A, B, C]
   
   Sort 2: Sort based on state-priority order:
   newPrefList = [A, B, C] => [B, A, C]
   ```
   Here, A will be 2nd and C will be third always as both have same priority so 
original (pref-list) order will be maintained.
   
   



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