originalPartitions.addAll(initialCluster.getPartitionIdsInZone(zoneId));
}
// Get an intermediate cluster where partitions that belong to the zone
// that is being dropped have been moved to the existing zones
Cluster interimCluster = RebalanceUtils.vacateZone(initialCluster, dropZoneId);
// Make sure that the intermediate cluster should have same number of
// partitions
RebalanceUtils.validateClusterPartitionCounts(initialCluster, interimCluster);
// Make sure that the intermediate cluster should have same number of
// nodes
RebalanceUtils.validateClusterNodeCounts(initialCluster, interimCluster);
// Make sure that the intermediate cluster doesn't have any partitons in
// the dropped zone
assertTrue("Zone being dropped has partitions. ZoneClipper didn't work properly",
interimCluster.getPartitionIdsInZone(dropZoneId).isEmpty());
// Make sure that the nodes being dropped don't host any partitions
for(Integer nodeId: interimCluster.getNodeIdsInZone(dropZoneId)) {
assertTrue("Nodes in the zone being dropped don't have empty partitions list",
interimCluster.getNodeById(nodeId).getPartitionIds().isEmpty());
}
Set<Integer> finalPartitions = new HashSet<Integer>();
for(Integer zoneId: interimCluster.getZoneIds()) {
finalPartitions.addAll(interimCluster.getPartitionIdsInZone(zoneId));
}
// Compare to original partition ids list
assertTrue("Original and interm partition ids don't match",
originalPartitions.equals(finalPartitions));
// Make sure that there is no data movement
RebalancePlan rebalancePlan = ClusterTestUtils.makePlan(initialCluster,
storeDefs,
interimCluster,
storeDefs);
// Make sure we have a plan
assertEquals(rebalancePlan.getPlan().size(), 1);
// Make sure there is no cross zones between zones in the plan
assertEquals(rebalancePlan.getPartitionStoresMovedXZone(), 0);
// Make sure there is no data movement between nodes
assertEquals(rebalancePlan.getPartitionStoresMoved(), 0);
for(Integer nodeId: interimCluster.getNodeIds()) {
Set<Integer> remainingNodes = Sets.symmetricDifference(interimCluster.getNodeIds(),
Sets.newHashSet(nodeId));
for(Integer otherNodeId: remainingNodes) {
assertTrue("Something went wrong as there is data movement between nodes",
rebalancePlan.getNodeMoveMap().get(nodeId, otherNodeId) == 0);
}
}
// Also get the adjusted store definitions, with the zone dropped
Cluster finalCluster = RebalanceUtils.dropZone(interimCluster, dropZoneId);
List<StoreDefinition> clippedStoreDefs = RebalanceUtils.dropZone(storeDefs, dropZoneId);
for(StoreDefinition storeDef: clippedStoreDefs) {
StoreDefinition orgStoreDef = StoreDefinitionUtils.getStoreDefinitionWithName(storeDefs,
storeDef.getName());
assertFalse("Clipped storedef has replication for dropped zone",
storeDef.getZoneReplicationFactor().containsKey(dropZoneId));
assertEquals("Clipped storedef has incorrect number of zones",
initialCluster.getZones().size() - 1,
storeDef.getZoneReplicationFactor().size());
assertEquals("Clipped storedef has incorrect total repfactor",
orgStoreDef.getReplicationFactor()
- orgStoreDef.getZoneReplicationFactor().get(dropZoneId),
storeDef.getReplicationFactor());
}
// Confirm that we would not route to any of the dropped nodes for any
// store.
Set<Integer> dropNodes = interimCluster.getNodeIdsInZone(dropZoneId);
for(StoreDefinition storeDef: clippedStoreDefs) {
StoreRoutingPlan routingPlan = new StoreRoutingPlan(finalCluster, storeDef);
Node[] partitionToNode = finalCluster.getPartitionIdToNodeArray();
for(int p = 0; p < partitionToNode.length; p++) {
List<Integer> replicaNodes = routingPlan.getReplicationNodeList(p);
assertFalse("Should not be routing to any dropped nodes",
replicaNodes.removeAll(dropNodes));
}