Search in sources :

Example 1 with PartitionMetadata

use of io.atomix.primitive.partition.PartitionMetadata in project atomix by atomix.

the class RaftPartitionGroup method buildPartitions.

private Collection<PartitionMetadata> buildPartitions(ClusterService clusterService) {
    int partitionSize = this.partitionSize;
    if (partitionSize == 0) {
        partitionSize = clusterService.getNodes().size();
    }
    List<NodeId> sorted = new ArrayList<>(clusterService.getNodes().stream().filter(node -> node.type() == Node.Type.CORE).map(Node::id).collect(Collectors.toSet()));
    Collections.sort(sorted);
    int length = sorted.size();
    int count = Math.min(partitionSize, length);
    Set<PartitionMetadata> metadata = Sets.newHashSet();
    for (int i = 0; i < partitions.size(); i++) {
        PartitionId partitionId = sortedPartitionIds.get(i);
        Set<NodeId> set = new HashSet<>(count);
        for (int j = 0; j < count; j++) {
            set.add(sorted.get((i + j) % length));
        }
        metadata.add(new PartitionMetadata(partitionId, set));
    }
    return metadata;
}
Also used : Node(io.atomix.cluster.Node) NodeId(io.atomix.cluster.NodeId) RaftProtocol(io.atomix.protocols.raft.RaftProtocol) ClusterEvent(io.atomix.cluster.ClusterEvent) LoggerFactory(org.slf4j.LoggerFactory) PartitionMetadata(io.atomix.primitive.partition.PartitionMetadata) CompletableFuture(java.util.concurrent.CompletableFuture) PartitionId(io.atomix.primitive.partition.PartitionId) ArrayList(java.util.ArrayList) StorageLevel(io.atomix.storage.StorageLevel) HashSet(java.util.HashSet) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Lists(com.google.common.collect.Lists) Partition(io.atomix.primitive.partition.Partition) PrimitiveProtocol(io.atomix.primitive.PrimitiveProtocol) Map(java.util.Map) ManagedPartitionGroup(io.atomix.primitive.partition.ManagedPartitionGroup) Futures(io.atomix.utils.concurrent.Futures) Logger(org.slf4j.Logger) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) Recovery(io.atomix.primitive.Recovery) Maps(com.google.common.collect.Maps) PartitionGroup(io.atomix.primitive.partition.PartitionGroup) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) File(java.io.File) ClusterEventListener(io.atomix.cluster.ClusterEventListener) List(java.util.List) PartitionManagementService(io.atomix.primitive.partition.PartitionManagementService) Type(io.atomix.primitive.PrimitiveProtocol.Type) ClusterService(io.atomix.cluster.ClusterService) Collections(java.util.Collections) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) Node(io.atomix.cluster.Node) NodeId(io.atomix.cluster.NodeId) ArrayList(java.util.ArrayList) PartitionMetadata(io.atomix.primitive.partition.PartitionMetadata) PartitionId(io.atomix.primitive.partition.PartitionId) HashSet(java.util.HashSet)

Aggregations

MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 ClusterEvent (io.atomix.cluster.ClusterEvent)1 ClusterEventListener (io.atomix.cluster.ClusterEventListener)1 ClusterService (io.atomix.cluster.ClusterService)1 Node (io.atomix.cluster.Node)1 NodeId (io.atomix.cluster.NodeId)1 PrimitiveProtocol (io.atomix.primitive.PrimitiveProtocol)1 Type (io.atomix.primitive.PrimitiveProtocol.Type)1 Recovery (io.atomix.primitive.Recovery)1 ManagedPartitionGroup (io.atomix.primitive.partition.ManagedPartitionGroup)1 Partition (io.atomix.primitive.partition.Partition)1 PartitionGroup (io.atomix.primitive.partition.PartitionGroup)1 PartitionId (io.atomix.primitive.partition.PartitionId)1 PartitionManagementService (io.atomix.primitive.partition.PartitionManagementService)1 PartitionMetadata (io.atomix.primitive.partition.PartitionMetadata)1