Skip to content

Commit

Permalink
Tweaks to PartitionBalance and RebalancePlan
Browse files Browse the repository at this point in the history
PartitionBalance
- calculate partition-stores per zone.
- This measure provides more context to evaluate the size of any plans to rebalance the cluster.

RebalancePlanCLI
- fix typo in verbose usage message
  • Loading branch information
jayjwylie committed Jun 28, 2013
1 parent 33ea454 commit a26a558
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
21 changes: 21 additions & 0 deletions src/java/voldemort/tools/PartitionBalance.java
Expand Up @@ -60,6 +60,7 @@ public class PartitionBalance {
private final Map<Integer, Integer> primaryAggNodeIdToPartitionCount;
private final Map<Integer, Integer> aggNodeIdToZonePrimaryCount;
private final Map<Integer, Integer> allAggNodeIdToPartitionCount;
private final Map<Integer, Integer> zoneIdToPartitionStoreCount;

public PartitionBalance(Cluster cluster, List<StoreDefinition> storeDefs) {
this.cluster = cluster;
Expand All @@ -69,6 +70,7 @@ public PartitionBalance(Cluster cluster, List<StoreDefinition> storeDefs) {

HashMap<StoreDefinition, Integer> uniqueStores = KeyDistributionGenerator.getUniqueStoreDefinitionsWithCounts(storeDefs);
Set<Integer> nodeIds = cluster.getNodeIds();
Set<Integer> zoneIds = cluster.getZoneIds();

builder.append("PARTITION DUMP\n");
this.primaryAggNodeIdToPartitionCount = Maps.newHashMap();
Expand All @@ -86,6 +88,11 @@ public PartitionBalance(Cluster cluster, List<StoreDefinition> storeDefs) {
allAggNodeIdToPartitionCount.put(nodeId, 0);
}

this.zoneIdToPartitionStoreCount = Maps.newHashMap();
for(Integer zoneId: zoneIds) {
zoneIdToPartitionStoreCount.put(zoneId, 0);
}

for(StoreDefinition storeDefinition: uniqueStores.keySet()) {
StoreRoutingPlan storeRoutingPlan = new StoreRoutingPlan(cluster, storeDefinition);

Expand Down Expand Up @@ -130,11 +137,25 @@ public PartitionBalance(Cluster cluster, List<StoreDefinition> storeDefs) {
allAggNodeIdToPartitionCount.put(nodeId,
allAggNodeIdToPartitionCount.get(nodeId)
+ (nodeIdToNaryCount.get(nodeId) * uniqueStores.get(storeDefinition)));

// Count partition-stores per-zone
int zoneId = cluster.getNodeById(nodeId).getZoneId();
zoneIdToPartitionStoreCount.put(zoneId,
zoneIdToPartitionStoreCount.get(zoneId)
+ (nodeIdToNaryCount.get(nodeId) * uniqueStores.get(storeDefinition)));
}
}

builder.append(Utils.NEWLINE).append(Utils.NEWLINE);

builder.append("PARTITION-STORES PER-ZONE:").append(Utils.NEWLINE);
for(Integer zoneId: zoneIds) {
builder.append("\tZone ID: " + zoneId + " : " + zoneIdToPartitionStoreCount.get(zoneId))
.append(Utils.NEWLINE);
}

builder.append(Utils.NEWLINE).append(Utils.NEWLINE);

Pair<Double, String> summary = summarizeBalance(primaryAggNodeIdToPartitionCount,
"AGGREGATE PRIMARY-PARTITION COUNT (across all stores)");
builder.append(summary.getSecond());
Expand Down
2 changes: 1 addition & 1 deletion src/java/voldemort/tools/RebalancePlanCLI.java
Expand Up @@ -91,7 +91,7 @@ private static void printUsage() {
help.append(" --final-cluster <clusterXML>\n");
help.append(" Optional:\n");
help.append(" --final-stores <storesXML> [ Needed for zone expansion ]\n");
help.append(" --batch <batch> [ Number of primary partitions to move in each rebalancing batch. ]\n");
help.append(" --batch-size <batchSize> [ Number of primary partitions to move in each rebalancing batch. ]\n");
help.append(" --output-dir <outputDir> [ Directory in which cluster metadata is dumped for each batch of the plan. ]\n");

try {
Expand Down
17 changes: 12 additions & 5 deletions test/unit/voldemort/tools/PartitionBalanceTest.java
Expand Up @@ -46,11 +46,17 @@ public class PartitionBalanceTest {

@Test
public void testBasicThingsThatShouldWork() {
new PartitionBalance(ClusterTestUtils.getZZCluster(),
ClusterTestUtils.getZZStoreDefsInMemory());

new PartitionBalance(ClusterTestUtils.getZZZCluster(),
ClusterTestUtils.getZZZStoreDefsInMemory());
PartitionBalance pb = new PartitionBalance(ClusterTestUtils.getZZCluster(),
ClusterTestUtils.getZZStoreDefsInMemory());
// Print out results so there is a test case that demonstrates toString
// method output for 2 zones
System.out.println(pb);

pb = new PartitionBalance(ClusterTestUtils.getZZZCluster(),
ClusterTestUtils.getZZZStoreDefsInMemory());
// Print out results so there is a test case that demonstrates toString
// method output for 3 zones
System.out.println(pb);
}

@Test
Expand Down Expand Up @@ -133,4 +139,5 @@ public void testNonContiguousZonesThatShouldWorkButDoNot() {
}
assertTrue(veCaught);
}

}

0 comments on commit a26a558

Please sign in to comment.