Class RoundRobinPartitionDistributor

java.lang.Object
io.atomix.raft.partition.RoundRobinPartitionDistributor
All Implemented Interfaces:
PartitionDistributor

public final class RoundRobinPartitionDistributor extends Object implements PartitionDistributor
This implementation of PartitionDistributor distributes the partitions in a round robin fashion over the set of members in the cluster.

Example distribution with 4 members, 5 partitions, and a replication factor of 3

 +------------------+----+----+----+---+
 | Partition \ Node | 0  | 1  | 2  | 3 |
 +------------------+----+----+----+---+
 |                1 | 3  | 2  | 1  |   |
 |                2 |    | 3  | 2  | 1 |
 |                3 | 1  |    | 3  | 2 |
 |                4 | 2  | 1  |    | 3 |
 |                5 | 3  | 1  | 2  |   |
 +------------------+----+----+----+---+
 
  • Constructor Details

    • RoundRobinPartitionDistributor

      public RoundRobinPartitionDistributor()
  • Method Details

    • distributePartitions

      public Set<PartitionMetadata> distributePartitions(Set<MemberId> clusterMembers, List<PartitionId> sortedPartitionIds, int replicationFactor)
      Description copied from interface: PartitionDistributor
      Provides the partition distribution based on the given list of partition IDs, cluster members, and the replication factor. The set of partitions returned is guaranteed to be correctly replicated.
      Specified by:
      distributePartitions in interface PartitionDistributor
      Parameters:
      clusterMembers - the set of members that can own partitions
      sortedPartitionIds - a sorted list of partition IDs
      replicationFactor - the replication factor for each partition
      Returns:
      a set of distributed partitions, each specifying which members they belong to