*/
public static Map<Integer, Set<Pair<Integer, Integer>>> getNodeIdToAllPartitions(final Cluster cluster,
final StoreDefinition storeDef,
boolean includePrimary) {
final RoutingStrategy routingStrategy = new RoutingStrategyFactory().updateRoutingStrategy(storeDef,
cluster);
final Map<Integer, Set<Pair<Integer, Integer>>> nodeIdToReplicas = new HashMap<Integer, Set<Pair<Integer, Integer>>>();
final Map<Integer, Integer> partitionToNodeIdMap = cluster.getPartitionIdToNodeIdMap();
// Map initialization.
for(Node node: cluster.getNodes()) {
nodeIdToReplicas.put(node.getId(), new HashSet<Pair<Integer, Integer>>());
}
// Track how many zones actually have partitions (and so replica types)
// in them.
int zonesWithPartitions = 0;
for(Integer zoneId: cluster.getZoneIds()) {
if(cluster.getNumberOfPartitionsInZone(zoneId) > 0) {
zonesWithPartitions++;
}
}
// Loops through all nodes
for(Node node: cluster.getNodes()) {
// Gets the partitions that this node was configured with.
for(Integer primary: node.getPartitionIds()) {
// Gets the list of replicating partitions.
List<Integer> replicaPartitionList = routingStrategy.getReplicatingPartitionList(primary);
if((replicaPartitionList.size() % zonesWithPartitions != 0)
|| ((replicaPartitionList.size() / zonesWithPartitions) != (storeDef.getReplicationFactor() / cluster.getNumberOfZones()))) {
// For zone expansion & shrinking, this warning is expected