use of com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupIdsOp in project hazelcast by hazelcast.
the class RaftInvocationManager method invokeGetMembersToCreateRaftGroup.
private void invokeGetMembersToCreateRaftGroup(String groupName, int groupSize, InternalCompletableFuture<RaftGroupId> resultFuture) {
RaftGroupId metadataGroupId = raftService.getMetadataGroupId();
InternalCompletableFuture<List<CPMemberInfo>> f1 = query(metadataGroupId, new GetActiveCPMembersOp(), LINEARIZABLE);
InternalCompletableFuture<Collection<RaftGroupId>> f2 = query(metadataGroupId, new GetRaftGroupIdsOp(), LINEARIZABLE);
f1.thenCombineAsync(f2, (cpMembers, groupIds) -> {
if (cpMembers.size() < groupSize) {
Exception e = new IllegalArgumentException("There are not enough active CP members to create CP group " + groupName + ". Active CP members: " + cpMembers.size() + ", Requested CP group size: " + groupSize);
resultFuture.completeExceptionally(e);
return null;
}
long groupIndex = generateRandomGroupIndex(groupIds);
List<RaftEndpoint> groupEndpoints = generateRandomGroupMembers(cpMembers, groupSize);
invokeCreateRaftGroup(groupName, groupSize, groupIndex, groupEndpoints, resultFuture);
return null;
}).exceptionally(t -> {
resultFuture.completeExceptionally(t);
return null;
});
}
Aggregations