xyuanlu commented on code in PR #3043: URL: https://github.com/apache/helix/pull/3043#discussion_r2165642513
########## helix-core/src/main/java/org/apache/helix/controller/stages/MessageGenerationPhase.java: ########## @@ -290,7 +325,67 @@ private void generateMessage(final Resource resource, final BaseControllerDataPr } // end of for-each-partition } - private boolean shouldCreateSTCancellation(Message pendingMessage, String desiredState, + /** + * Calculate the current active replica count based on state model type. + * The count includes replicas in top states, secondary top states (excluding OFFLINE), + * and ERROR states since helix considers them active.Count excludes OFFLINE and DROPPED states. + * @param currentStateMap Map of instance name to current state for this partition, representing + * the actual state of each replica before any pending transitions + * @param stateModelDef State model definition containing the state hierarchy and transition rules + * used to determine which states are considered active + * @return The number of replicas currently in active states, used to determine the + * currentActiveReplicaNumber for the partition. + */ + private int calculateCurrentActiveReplicaCount(Map<String, String> currentStateMap, + StateModelDefinition stateModelDef) { + List<String> activeSecondaryTopStates = getActiveSecondaryTopStates(stateModelDef); + return (int) currentStateMap.values().stream() + .filter(state -> stateModelDef.getTopState().contains(state) // Top states (MASTER, ONLINE, + // LEADER) + || activeSecondaryTopStates.contains(state) // Active secondary states (SLAVE, STANDBY, + // BOOTSTRAP) + || HelixDefinedState.ERROR.name().equals(state) // ERROR states (still considered + // active) + // DROPPED and OFFLINE are automatically excluded by getActiveSecondaryTopStates() + ).count(); Review Comment: nit: activeSecondaryTopStates is only used once, can be inline -- 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: reviews-unsubscr...@helix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org For additional commands, e-mail: reviews-h...@helix.apache.org