Created
June 23, 2011 23:39
-
-
Save rsumbaly/1043906 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void partitionLoad(Cluster cluster, List<StoreDefinition> storeDefs) { | |
HashMap<StoreDefinition, Integer> uniqueStoreDefs = getUniqueStoreDefinitionsWithCounts(storeDefs); | |
for(Entry<StoreDefinition, Integer> storeDefCounts: uniqueStoreDefs.entrySet()) { | |
StoreDefinition storeDef = storeDefCounts.getKey(); | |
RoutingStrategy strategy = new RoutingStrategyFactory().updateRoutingStrategy(storeDef, | |
cluster); | |
HashMap<Integer, Integer> partitionToCountMapping = Maps.newHashMap(); | |
for(int partitionId = 0; partitionId < cluster.getNumberOfPartitions(); partitionId++) { | |
List<Integer> partitionList = strategy.getReplicatingPartitionList(partitionId); | |
for(int partition: partitionList) { | |
int currentCount = 0; | |
if(partitionToCountMapping.containsKey(partition)) { | |
currentCount = partitionToCountMapping.get(partition); | |
} | |
currentCount++; | |
partitionToCountMapping.put(partition, currentCount); | |
} | |
} | |
// Convert partition -> number to number -> [ partition ] | |
TreeMultimap<Integer, Integer> hitsToPartitions = TreeMultimap.create(); | |
for(Entry<Integer, Integer> partitionToCountEntry: partitionToCountMapping.entrySet()) { | |
hitsToPartitions.put(partitionToCountEntry.getValue(), | |
partitionToCountEntry.getKey()); | |
} | |
System.out.println("For " | |
+ storeDefCounts.getValue() | |
+ " stores with replication factor " | |
+ storeDef.getReplicationFactor() | |
+ ((storeDef.getRoutingStrategyType() | |
.compareTo(RoutingStrategyType.ZONE_STRATEGY) == 0) ? " - " | |
+ storeDef.getZoneReplicationFactor() | |
: "")); | |
for(int hit: hitsToPartitions.keySet()) { | |
System.out.println("Hits " + hit + " - " + hitsToPartitions.get(hit)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment