/** * Takes snapshots of all Raft partitions. * * @return a future to be completed once snapshots have been taken */ public CompletableFuture<Void> snapshot() { return Futures.allOf(config.getMembers().stream() .map(MemberId::from) .map(id -> communicationService.send(snapshotSubject, null, id, SNAPSHOT_TIMEOUT)) .collect(Collectors.toList())) .thenApply(v -> null); }
private Collection<PartitionMetadata> buildPartitions() { List<MemberId> sorted = new ArrayList<>(config.getMembers().stream() .map(MemberId::from) .collect(Collectors.toSet())); Collections.sort(sorted); int partitionSize = this.partitionSize; if (partitionSize == 0) { partitionSize = sorted.size(); } 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<MemberId> 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; }