Github user kongweihan commented on a diff in the pull request: https://github.com/apache/helix/pull/89#discussion_r115849569 --- Diff: helix-core/src/main/java/org/apache/helix/controller/stages/CurrentStateOutput.java --- @@ -260,13 +260,72 @@ public Message getPendingState(String resourceName, Partition partition, String return partitionSet; } + /** + * Get the partitions count for each participant with the pending state and given resource state model + * @param resourceStateModel specified resource state model to look up + * @param state specified pending resource state to look up + * @return set of participants to partitions mapping + */ + public Map<String, Integer> getPartitionCountWithPendingState(String resourceStateModel, String state) { + Map<String, Integer> pendingPartitionCount = new HashMap<String, Integer>(); + for (String resource : _pendingStateMap.keySet()) { + String stateModel = _resourceStateModelMap.get(resource); + if (stateModel != null && stateModel.equals(resourceStateModel) + || stateModel == null && resourceStateModel == null) { + for (Partition partition : _pendingStateMap.get(resource).keySet()) { + Map<String, Message> partitionMessage = _pendingStateMap.get(resource).get(partition); + for (Map.Entry<String, Message> participantMap : partitionMessage.entrySet()) { + String participant = participantMap.getKey(); + if (!pendingPartitionCount.containsKey(participant)) { + pendingPartitionCount.put(participant, 0); + } + String toState = participantMap.getValue().getToState(); + if (toState != null && toState.equals(state) || toState == null && state == null) { + pendingPartitionCount.put(participant, pendingPartitionCount.get(participant) + 1); + } + } + } + } + } + return pendingPartitionCount; + } + + /** + * Get the partitions count for each participant in the current state and with given resource state model + * @param resourceStateModel specified resource state model to look up + * @param state specified current resource state to look up + * @return set of participants to partitions mapping + */ + public Map<String, Integer> getPartitionCountWithCurrentState(String resourceStateModel, String state) { --- End diff -- This is similar with the above method, would it be better to combine them together? I see that `_pendingStateMap` contains Messages instead of Strings, making it a bit hard to abstract. But look, its name is "_pendingStateMap", shouldn't it contain the pending state, instead of the message?
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---