Search in sources :

Example 16 with RaftEndpoint

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

the class MetadataRaftGroupManager method initMembershipChangeScheduleForLeavingMember.

private boolean initMembershipChangeScheduleForLeavingMember(long commitIndex, CPMemberInfo leavingMember) {
    List<CPGroupId> leavingGroupIds = new ArrayList<>();
    List<CPGroupMembershipChange> changes = new ArrayList<>();
    for (CPGroupInfo group : groups.values()) {
        CPGroupId groupId = group.id();
        if (!group.containsMember(leavingMember.toRaftEndpoint()) || group.status() == DESTROYED) {
            continue;
        }
        CPMemberInfo substitute = findSubstitute(group);
        RaftEndpoint substituteEndpoint = substitute != null ? substitute.toRaftEndpoint() : null;
        leavingGroupIds.add(groupId);
        changes.add(new CPGroupMembershipChange(groupId, group.getMembersCommitIndex(), group.memberImpls(), substituteEndpoint, leavingMember.toRaftEndpoint()));
    }
    if (changes.isEmpty()) {
        if (logger.isFineEnabled()) {
            logger.fine("Removing " + leavingMember + " directly since it is not present in any CP group.");
        }
        removeActiveMember(commitIndex, leavingMember);
        return true;
    }
    membershipChangeSchedule = MembershipChangeSchedule.forLeavingMember(singletonList(commitIndex), leavingMember, changes);
    if (logger.isFineEnabled()) {
        logger.info(leavingMember + " will be removed from " + changes);
    } else {
        logger.info(leavingMember + " will be removed from " + leavingGroupIds);
    }
    return false;
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ArrayList(java.util.ArrayList) CPGroupMembershipChange(com.hazelcast.cp.internal.MembershipChangeSchedule.CPGroupMembershipChange)

Example 17 with RaftEndpoint

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

the class MetadataRaftGroupManager method createRaftGroup.

public CPGroupSummary createRaftGroup(String groupName, Collection<RaftEndpoint> groupEndpoints, long groupId) {
    checkFalse(equalsIgnoreCase(METADATA_CP_GROUP_NAME, groupName), groupName + " is reserved for internal usage!");
    checkMetadataGroupInitSuccessful();
    // keep configuration on every metadata node
    CPGroupInfo group = getRaftGroupByName(groupName);
    if (group != null) {
        if (group.memberCount() == groupEndpoints.size()) {
            if (logger.isFineEnabled()) {
                logger.fine("CP group " + groupName + " already exists.");
            }
            return group.toSummary(activeMembers);
        }
        String msg = group.id() + " already exists with a different size: " + group.memberCount();
        logger.severe(msg);
        throw new IllegalStateException(msg);
    }
    group = getRaftGroupById(groupId);
    if (group != null) {
        throw new CannotCreateRaftGroupException("Cannot create CP group: " + groupName + " with members: " + groupEndpoints + " because group index: " + groupId + " already belongs to " + group.name());
    }
    Map<UUID, CPMemberInfo> activeMembersMap = getActiveMembersMap();
    CPMemberInfo leavingMember = membershipChangeSchedule != null ? membershipChangeSchedule.getLeavingMember() : null;
    for (RaftEndpoint groupEndpoint : groupEndpoints) {
        if ((leavingMember != null && groupEndpoint.getUuid().equals(leavingMember.getUuid())) || !activeMembersMap.containsKey(groupEndpoint.getUuid())) {
            String msg = "Cannot create CP group: " + groupName + " since " + groupEndpoint + " is not active";
            if (logger.isFineEnabled()) {
                logger.fine(msg);
            }
            throw new CannotCreateRaftGroupException(msg);
        }
    }
    return createRaftGroup(new CPGroupInfo(new RaftGroupId(groupName, getGroupIdSeed(), groupId), groupEndpoints));
}
Also used : CannotCreateRaftGroupException(com.hazelcast.cp.internal.exception.CannotCreateRaftGroupException) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) UUID(java.util.UUID)

Example 18 with RaftEndpoint

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

the class MetadataRaftGroupManager method createRaftGroup.

private CPGroupSummary createRaftGroup(CPGroupInfo group) {
    addRaftGroup(group);
    Map<UUID, CPMemberInfo> activeMembersMap = getActiveMembersMap();
    List<CPMemberInfo> members = new ArrayList<>();
    for (RaftEndpoint member : group.members()) {
        members.add(activeMembersMap.get(member.getUuid()));
    }
    logger.info("New " + group.id() + " is created with " + members);
    return group.toSummary(activeMembers);
}
Also used : RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Example 19 with RaftEndpoint

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

the class RaftService method getLeadedGroups.

public Collection<CPGroupId> getLeadedGroups() {
    Collection<CPGroupId> groupIds = new ArrayList<>();
    RaftEndpoint localEndpoint = getLocalCPEndpoint();
    for (RaftNode raftNode : nodes.values()) {
        if (CPGroup.METADATA_CP_GROUP_NAME.equals(raftNode.getGroupId().getName())) {
            // Ignore metadata group
            continue;
        }
        RaftEndpoint leader = raftNode.getLeader();
        if (leader != null && leader.equals(localEndpoint)) {
            groupIds.add(raftNode.getGroupId());
        }
    }
    return groupIds;
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ArrayList(java.util.ArrayList) RaftNode(com.hazelcast.cp.internal.raft.impl.RaftNode) RaftNodeImpl.newRaftNode(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl.newRaftNode)

Example 20 with RaftEndpoint

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

the class CPGroupInfo method toSummary.

CPGroupSummary toSummary(Collection<CPMemberInfo> cpMembers) {
    Map<UUID, CPMemberInfo> cpMembersMap = new HashMap<>();
    for (CPMemberInfo cpMember : cpMembers) {
        cpMembersMap.put(cpMember.getUuid(), cpMember);
    }
    // we should preserve the member ordering so we iterate over group members instead of all cp members
    List<CPMember> groupEndpoints = new ArrayList<>();
    for (RaftEndpoint endpoint : members) {
        CPMemberInfo memberInfo = cpMembersMap.get(endpoint.getUuid());
        if (memberInfo == null) {
            continue;
        }
        groupEndpoints.add(memberInfo);
    }
    if (groupEndpoints.size() != members.size()) {
        throw new IllegalStateException("Missing CP member in active CP members: " + cpMembers + " for " + this);
    }
    return new CPGroupSummary(id, status, initialMembers, groupEndpoints);
}
Also used : HashMap(java.util.HashMap) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ArrayList(java.util.ArrayList) UUID(java.util.UUID) CPMember(com.hazelcast.cp.CPMember)

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