csudharsanan commented on code in PR #3043:
URL: https://github.com/apache/helix/pull/3043#discussion_r2138378073
##########
helix-core/src/main/java/org/apache/helix/controller/stages/MessageGenerationPhase.java:
##########
@@ -290,6 +321,79 @@ private void generateMessage(final Resource resource,
final BaseControllerDataPr
} // end of for-each-partition
}
+ /**
+ * Calculate the target active replica count after state convergence.
+ * This method counts only replicas that will be actively serving traffic
after all
+ * state transitions complete. It excludes replicas being dropped or in
inactive states.
+ *
+ * @param instanceStateMap Map of instance to desired state
+ * @param stateModelDef The state model definition
+ * @return Number of active replicas after convergence
+ */
+ private int calculateTargetActiveReplicaCount(Map<String, String>
instanceStateMap,
+ StateModelDefinition stateModelDef) {
+ int targetActiveReplicaCount = 0;
+ String initialState = stateModelDef.getInitialState();
+
+ for (String desiredState : instanceStateMap.values()) {
+ // Count potential active replicas after convergence (not initial
state/dropped state)
+ // Note : calling it potential as counting active replicas after
convergence is hard as upward state transitions are in progress too.
+ if (desiredState != null && !desiredState.equals(initialState)
+ && !desiredState.equals(NO_DESIRED_STATE)
+ && !desiredState.equals(HelixDefinedState.DROPPED.name())) {
+ targetActiveReplicaCount++;
+ }
+ }
+
+ return targetActiveReplicaCount;
+ }
+
+ /**
+ * Check if a state is a second top state
+ * @param state The state to check
+ * @param stateModelDef The state model definition
+ * @return True if it's a second top state, false otherwise
+ */
+ private boolean isSecondTopState(String state, StateModelDefinition
stateModelDef) {
+ return stateModelDef.getSecondTopStates().contains(state);
+ }
+
+ /**
+ * Get pending upward state transition messages from non-second top state to
second top or top
+ * state
+ * @param resourceName The resource name
+ * @param partition The partition
+ * @param currentStateOutput The current state output
+ * @param stateModelDef The state model definition
+ * @return List of pending messages for upward state transitions
+ */
+ private List<Message> getPendingTransitionsToTopOrSecondTopStates(String
resourceName,
+ Partition partition, CurrentStateOutput currentStateOutput,
+ StateModelDefinition stateModelDef) {
+ List<Message> pendingUpwardSTMessages = new ArrayList<>();
+
+ // Instance -> PendingMessage
+ Map<String, Message> pendingMessages =
+ currentStateOutput.getPendingMessageMap(resourceName, partition);
+
+ if (pendingMessages != null && !pendingMessages.isEmpty()) {
+ for (Message message : pendingMessages.values()) {
+ String fromState = message.getFromState();
+ String toState = message.getToState();
+
+ // Check if it's an upward state transition from non-second top state
to second top or top
+ // state
+ if (stateModelDef.isUpwardStateTransition(fromState, toState)
+ && !isSecondTopState(fromState, stateModelDef)
+ && (isSecondTopState(toState, stateModelDef) ||
stateModelDef.getTopState().contains(toState))) {
Review Comment:
SLAVE → MASTER transitions are already prioritized as recovery rebalance in
Helix's existing pipeline.
This feature specifically targets load balancing scenarios: prioritizing
OFFLINE → SLAVE transitions that bring us TO min-active-replica vs BEYOND
min-active-replica. Recovery rebalance already handles secondary-to-top with
higher priority, so we are excluding them here.
--
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]