xyuanlu commented on code in PR #3043:
URL: https://github.com/apache/helix/pull/3043#discussion_r2165637115
##########
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();
+ }
+
+ /**
+ * Get active secondary top states - states that are not non-serving states
like OFFLINE and DROPPED.
+ * Reasons for elimination:
+ * - getSecondTopStates() can include OFFLINE as a secondary top state in
some state models.
+ * Example - OnlineOffline:
+ * getSecondTopStates() = ["OFFLINE"] as it transitions to ONLINE.
+ * After filtering: activeSecondaryTopStates=[] (removes "OFFLINE" as it's
not a serving state).
+ * @param stateModelDef State model definition containing state hierarchy
information
+ */
+ private List<String> getActiveSecondaryTopStates(StateModelDefinition
stateModelDef) {
+ return stateModelDef.getSecondTopStates().stream()
+ // Remove non-serving states
+ .filter(state -> !OFFLINE.equals(state) &&
!HelixDefinedState.DROPPED.name().equals(state))
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * Determines if the given state is considered active based on the state
model type.
+ * Active states include: top states, active secondary top states (excluding
OFFLINE),
+ * and ERROR states. Active states exclude OFFLINE and DROPPED states.
+ * ERROR state replicas are always considered active in HELIX as they do not
+ * affect availability.
+ * @param state The state to check (can be current state or target state)
+ * @param stateModelDef State model definition containing state hierarchy
information
+ * @return true if the state is considered active, false otherwise
+ */
+ private boolean isStateActive(String state, StateModelDefinition
stateModelDef) {
Review Comment:
nit:
alignment
--
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]