@ Override public List < Integer > getReplicatingPartitionList ( int index ) { List < Node > preferenceNodesList = new ArrayList < Node > ( getNumReplicas ( ) ) ; List < Integer > replicationPartitionsList = new ArrayList < Integer > ( getNumReplicas ( ) ) ; // Copy Zone based Replication Factor HashMap < Integer , Integer > requiredRepFactor = new HashMap < Integer , Integer > ( ) ; requiredRepFactor . putAll ( zoneReplicationFactor ) ; // Cross-check if individual zone replication factor equals global int sum = 0 ; for ( Integer zoneRepFactor : requiredRepFactor . values ( ) ) { sum += zoneRepFactor ; } if ( sum != getNumReplicas ( ) ) throw new IllegalArgumentException ( "Number of zone replicas is not equal to the total replication factor" ) ; if ( getPartitionToNode ( ) . length == 0 ) { return new ArrayList < Integer > ( 0 ) ; } for ( int i = 0 ; i < getPartitionToNode ( ) . length ; i ++ ) { // add this one if we haven't already, and it can satisfy some zone // replicationFactor Node currentNode = getNodeByPartition ( index ) ; if ( ! preferenceNodesList . contains ( currentNode ) ) { preferenceNodesList . add ( currentNode ) ; if ( checkZoneRequirement ( requiredRepFactor , currentNode . getZoneId ( ) ) ) replicationPartitionsList . add ( index ) ; } // if we have enough, go home if ( replicationPartitionsList . size ( ) >= getNumReplicas ( ) ) return replicationPartitionsList ; // move to next clockwise slot on the ring index = ( index + 1 ) % getPartitionToNode ( ) . length ; } // we don't have enough, but that may be okay return replicationPartitionsList ; }
Get the replication partitions list for the given partition .