xyuanlu commented on code in PR #2702:
URL: https://github.com/apache/helix/pull/2702#discussion_r1402752730
##########
helix-core/src/main/java/org/apache/helix/controller/stages/BestPossibleStateCalcStage.java:
##########
@@ -121,6 +131,47 @@ public void process(ClusterEvent event) throws Exception {
});
}
+ private void addSwapInInstancesToBestPossibleState(Map<String, Resource>
resourceMap,
+ BestPossibleStateOutput bestPossibleStateOutput,
ResourceControllerDataProvider cache) {
+ // 1. Get all SWAP_OUT instances and corresponding SWAP_IN instance pairs
in the cluster.
+ Map<String, String> swapOutToSwapInInstancePairs =
cache.getSwapOutToSwapInInstancePairs();
+ // 2. Get all enabled and live SWAP_IN instances in the cluster.
+ Set<String> enabledLiveSwapInInstances =
cache.getEnabledLiveSwapInInstanceNames();
+ // 3. For each SWAP_OUT instance in any of the preferenceLists, add the
corresponding SWAP_IN instance to the end.
+ // Skipping this when there are not SWAP_IN instances ready(enabled and
live) will reduce computation time when there is not an active
+ // swap occurring.
+ if (!enabledLiveSwapInInstances.isEmpty() &&
!cache.isMaintenanceModeEnabled()) {
+ resourceMap.forEach((resourceName, resource) -> {
+ StateModelDefinition stateModelDef =
cache.getStateModelDef(resource.getStateModelDefRef());
+
bestPossibleStateOutput.getResourceStatesMap().get(resourceName).getStateMap()
+ .forEach((partition, stateMap) -> {
+ Set<String> commonInstances = new HashSet<>(stateMap.keySet());
+ commonInstances.retainAll(swapOutToSwapInInstancePairs.keySet());
+
+ if (commonInstances.isEmpty()) {
+ return;
+ }
+
+ for (String swapOutInstance : commonInstances) {
+ String swapInInstanceState;
+ // If the swap-out instance's replica is a topState and the
StateModel allows for
+ // another replica with the topState to be added, set the
swap-in instance's replica
+ // to the topState. Otherwise, set the swap-in instance's
replica to the secondTopState.
+ if
(stateMap.get(swapOutInstance).equals(stateModelDef.getTopState()) &&
+
AbstractRebalancer.getStateCount(stateModelDef.getTopState(), stateModelDef,
+ stateMap.size() + 1, stateMap.size() + 1) >
stateMap.size()) {
+ swapInInstanceState = stateModelDef.getTopState();
+ } else {
+ swapInInstanceState =
stateModelDef.getSecondTopStates().iterator().next();
Review Comment:
We are assuming swap out instance has 2nd top state here. Doule check on
think.
--
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]