Search in sources :

Example 36 with RaftEndpoint

use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.

the class MetadataRaftGroupManager method checkSafeToRemoveIfCPMemberLeaving.

private boolean checkSafeToRemoveIfCPMemberLeaving(MembershipChangeSchedule schedule) {
    CPMemberInfo leavingMember = schedule.getLeavingMember();
    if (leavingMember == null) {
        return false;
    }
    if (schedule.getChanges().size() > 0) {
        return false;
    }
    RaftEndpoint leavingEndpoint = leavingMember.toRaftEndpoint();
    for (CPGroupInfo group : groups.values()) {
        if (group.containsMember(leavingEndpoint)) {
            if (group.status() != DESTROYED) {
                return false;
            } else if (logger.isFineEnabled()) {
                logger.warning("Leaving " + leavingMember + " was in the destroyed " + group.id());
            }
        }
    }
    return true;
}
Also used : RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint)

Example 37 with RaftEndpoint

use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.

the class MetadataRaftGroupManager method sendTerminateRaftNodeOpsForDestroyedGroup.

private void sendTerminateRaftNodeOpsForDestroyedGroup(CPGroupInfo group) {
    Map<UUID, CPMemberInfo> activeMembersMap = getActiveMembersMap();
    CPMemberInfo localCPMember = getLocalCPMember();
    if (localCPMember == null) {
        return;
    }
    RaftEndpoint localEndpoint = localCPMember.toRaftEndpoint();
    OperationService operationService = nodeEngine.getOperationService();
    for (RaftEndpoint endpoint : group.members()) {
        if (endpoint.equals(localEndpoint)) {
            terminateRaftNodeAsync(group.id());
        } else {
            Operation op = new TerminateRaftNodesOp(Collections.singleton(group.id()));
            CPMemberInfo cpMember = activeMembersMap.get(endpoint.getUuid());
            operationService.invokeOnTarget(SERVICE_NAME, op, cpMember.getAddress());
        }
    }
}
Also used : RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Operation(com.hazelcast.spi.impl.operationservice.Operation) UUID(java.util.UUID) TerminateRaftNodesOp(com.hazelcast.cp.internal.raftop.metadata.TerminateRaftNodesOp)

Example 38 with RaftEndpoint

use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.

the class MetadataRaftGroupManager method applyMembershipChange.

private boolean applyMembershipChange(CPGroupMembershipChange change, CPGroupInfo group, long expectedMembersCommitIndex, long newMembersCommitIndex) {
    RaftEndpoint addedMember = change.getMemberToAdd();
    RaftEndpoint removedMember = change.getMemberToRemove();
    if (group.applyMembershipChange(removedMember, addedMember, expectedMembersCommitIndex, newMembersCommitIndex)) {
        if (logger.isFineEnabled()) {
            logger.fine("Applied add-member: " + (addedMember != null ? addedMember : "-") + " and remove-member: " + (removedMember != null ? removedMember : "-") + " in " + group.id() + " with new members commit index: " + newMembersCommitIndex);
        }
        return true;
    }
    logger.severe("Could not apply add-member: " + (addedMember != null ? addedMember : "-") + " and remove-member: " + (removedMember != null ? removedMember : "-") + " in " + group + " with new members commit index: " + newMembersCommitIndex + ", expected members commit index: " + expectedMembersCommitIndex + ", known members commit index: " + group.getMembersCommitIndex());
    return false;
}
Also used : RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint)

Example 39 with RaftEndpoint

use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint 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)

Example 40 with RaftEndpoint

use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.

the class CPGroupInfo method writeData.

@Override
public void writeData(ObjectDataOutput out) throws IOException {
    out.writeObject(id);
    out.writeInt(initialMembers.size());
    for (RaftEndpoint member : initialMembers) {
        out.writeObject(member);
    }
    out.writeLong(membersCommitIndex);
    out.writeInt(members.size());
    for (RaftEndpoint member : members) {
        out.writeObject(member);
    }
    out.writeString(status.toString());
}
Also used : RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint)

Aggregations

RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)57 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)14 QuickTest (com.hazelcast.test.annotation.QuickTest)14 Test (org.junit.Test)14 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)8 RaftState (com.hazelcast.cp.internal.raft.impl.state.RaftState)7 ArrayList (java.util.ArrayList)7 CPMember (com.hazelcast.cp.CPMember)6 RaftLog (com.hazelcast.cp.internal.raft.impl.log.RaftLog)6 UUID (java.util.UUID)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 CPGroupId (com.hazelcast.cp.CPGroupId)5 TestRaftEndpoint (com.hazelcast.cp.internal.raft.impl.testing.TestRaftEndpoint)5 LinkedHashSet (java.util.LinkedHashSet)4 LogEntry (com.hazelcast.cp.internal.raft.impl.log.LogEntry)3 CPSubsystemException (com.hazelcast.cp.exception.CPSubsystemException)2 NotLeaderException (com.hazelcast.cp.exception.NotLeaderException)2 CannotCreateRaftGroupException (com.hazelcast.cp.internal.exception.CannotCreateRaftGroupException)2 RaftStateStore (com.hazelcast.cp.internal.raft.impl.persistence.RaftStateStore)2 LeaderState (com.hazelcast.cp.internal.raft.impl.state.LeaderState)2