Search in sources :

Example 1 with GetRaftGroupIdsOp

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;
    });
}
Also used : Collections.shuffle(java.util.Collections.shuffle) ChangeRaftGroupMembershipOp(com.hazelcast.cp.internal.operation.ChangeRaftGroupMembershipOp) AbstractUnsafeRaftOp(com.hazelcast.cp.internal.operation.unsafe.AbstractUnsafeRaftOp) MembershipChangeMode(com.hazelcast.cp.internal.raft.MembershipChangeMode) DEFAULT_DESERIALIZE_RESULT(com.hazelcast.spi.impl.operationservice.InvocationBuilder.DEFAULT_DESERIALIZE_RESULT) RaftInvocationContext(com.hazelcast.spi.impl.operationservice.impl.RaftInvocationContext) CannotCreateRaftGroupException(com.hazelcast.cp.internal.exception.CannotCreateRaftGroupException) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ArrayList(java.util.ArrayList) CreateRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.CreateRaftGroupOp) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ClusterService(com.hazelcast.internal.cluster.ClusterService) LINEARIZABLE(com.hazelcast.cp.internal.raft.QueryPolicy.LINEARIZABLE) ILogger(com.hazelcast.logging.ILogger) Operation(com.hazelcast.spi.impl.operationservice.Operation) Invocation(com.hazelcast.spi.impl.operationservice.impl.Invocation) CreateRaftNodeOp(com.hazelcast.cp.internal.raftop.metadata.CreateRaftNodeOp) GetRaftGroupIdsOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupIdsOp) CPGroupId(com.hazelcast.cp.CPGroupId) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) HazelcastException(com.hazelcast.core.HazelcastException) NodeEngine(com.hazelcast.spi.impl.NodeEngine) DefaultRaftReplicateOp(com.hazelcast.cp.internal.operation.DefaultRaftReplicateOp) UnsafeRaftReplicateOp(com.hazelcast.cp.internal.operation.unsafe.UnsafeRaftReplicateOp) Collection(java.util.Collection) RandomPicker(com.hazelcast.internal.util.RandomPicker) QueryPolicy(com.hazelcast.cp.internal.raft.QueryPolicy) Collectors(java.util.stream.Collectors) DestroyRaftGroupOp(com.hazelcast.cp.internal.operation.DestroyRaftGroupOp) RaftQueryOp(com.hazelcast.cp.internal.operation.RaftQueryOp) GetActiveCPMembersOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp) ClusterProperty(com.hazelcast.spi.properties.ClusterProperty) CP_SUBSYSTEM_EXECUTOR(com.hazelcast.cp.internal.RaftService.CP_SUBSYSTEM_EXECUTOR) List(java.util.List) CPMember(com.hazelcast.cp.CPMember) RaftInvocation(com.hazelcast.spi.impl.operationservice.impl.RaftInvocation) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Comparator(java.util.Comparator) UnsafeRaftQueryOp(com.hazelcast.cp.internal.operation.unsafe.UnsafeRaftQueryOp) Collection(java.util.Collection) GetRaftGroupIdsOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupIdsOp) ArrayList(java.util.ArrayList) List(java.util.List) GetActiveCPMembersOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp) CannotCreateRaftGroupException(com.hazelcast.cp.internal.exception.CannotCreateRaftGroupException) HazelcastException(com.hazelcast.core.HazelcastException)

Aggregations

HazelcastException (com.hazelcast.core.HazelcastException)1 CPGroupId (com.hazelcast.cp.CPGroupId)1 CPMember (com.hazelcast.cp.CPMember)1 CP_SUBSYSTEM_EXECUTOR (com.hazelcast.cp.internal.RaftService.CP_SUBSYSTEM_EXECUTOR)1 CannotCreateRaftGroupException (com.hazelcast.cp.internal.exception.CannotCreateRaftGroupException)1 ChangeRaftGroupMembershipOp (com.hazelcast.cp.internal.operation.ChangeRaftGroupMembershipOp)1 DefaultRaftReplicateOp (com.hazelcast.cp.internal.operation.DefaultRaftReplicateOp)1 DestroyRaftGroupOp (com.hazelcast.cp.internal.operation.DestroyRaftGroupOp)1 RaftQueryOp (com.hazelcast.cp.internal.operation.RaftQueryOp)1 AbstractUnsafeRaftOp (com.hazelcast.cp.internal.operation.unsafe.AbstractUnsafeRaftOp)1 UnsafeRaftQueryOp (com.hazelcast.cp.internal.operation.unsafe.UnsafeRaftQueryOp)1 UnsafeRaftReplicateOp (com.hazelcast.cp.internal.operation.unsafe.UnsafeRaftReplicateOp)1 MembershipChangeMode (com.hazelcast.cp.internal.raft.MembershipChangeMode)1 QueryPolicy (com.hazelcast.cp.internal.raft.QueryPolicy)1 LINEARIZABLE (com.hazelcast.cp.internal.raft.QueryPolicy.LINEARIZABLE)1 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)1 CreateRaftGroupOp (com.hazelcast.cp.internal.raftop.metadata.CreateRaftGroupOp)1 CreateRaftNodeOp (com.hazelcast.cp.internal.raftop.metadata.CreateRaftNodeOp)1 GetActiveCPMembersOp (com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp)1 GetRaftGroupIdsOp (com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupIdsOp)1