public static Cluster vacateZone ( Cluster currentCluster , int dropZoneId ) { Cluster returnCluster = Cluster . cloneCluster ( currentCluster ) ; // Go over each node in the zone being dropped for ( Integer nodeId : currentCluster . getNodeIdsInZone ( dropZoneId ) ) { // For each node grab all the partitions it hosts for ( Integer partitionId : currentCluster . getNodeById ( nodeId ) . getPartitionIds ( ) ) { // Now for each partition find a new home..which would be a node // in one of the existing zones int finalZoneId = - 1 ; int finalNodeId = - 1 ; int adjacentPartitionId = partitionId ; do { adjacentPartitionId = ( adjacentPartitionId + 1 ) % currentCluster . getNumberOfPartitions ( ) ; finalNodeId = currentCluster . getNodeForPartitionId ( adjacentPartitionId ) . getId ( ) ; finalZoneId = currentCluster . getZoneForPartitionId ( adjacentPartitionId ) . getId ( ) ; if ( adjacentPartitionId == partitionId ) { logger . error ( "PartitionId " + partitionId + "stays unchanged \n" ) ; } else { logger . info ( "PartitionId " + partitionId + " goes together with partition " + adjacentPartitionId + " on node " + finalNodeId + " in zone " + finalZoneId ) ; returnCluster = UpdateClusterUtils . createUpdatedCluster ( returnCluster , finalNodeId , Lists . newArrayList ( partitionId ) ) ; } } while ( finalZoneId == dropZoneId ) ; } } return returnCluster ; }
Given the current cluster and a zone id that needs to be dropped this method will remove all partitions from the zone that is being dropped and move it to the existing zones . The partitions are moved intelligently so as not to avoid any data movement in the existing zones .