Github user jiajunwang commented on a diff in the pull request: https://github.com/apache/helix/pull/89#discussion_r116576058 --- 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 -- They are different methods. As you said, types in the maps are different. So will need to introduce additional code for processing the Message map. As a result, final code lines won't be reduced significantly. More like: 1. Convert Map<String, Map<Partition, Map<String, Message>>> _pendingStateMap to Map<String, Map<Partition, Map<String, String>>> tempPendingStateMap 2. Call method public Map<String, Integer> getPartitionCount(String resourceStateModel, String state, Map<String, Map<Partition, Map<String, String>>> stateMap) to get the final result. Please let me know if you have a better idea. Otherwise, it seems not quite worth the change.
--- 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. ---