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;
}
Aggregations