Search in sources :

Example 1 with CPGroupMembershipChange

use of com.hazelcast.cp.internal.MembershipChangeSchedule.CPGroupMembershipChange in project hazelcast by hazelcast.

the class MetadataRaftGroupManager method completeRaftGroupMembershipChanges.

public MembershipChangeSchedule completeRaftGroupMembershipChanges(long commitIndex, Map<CPGroupId, BiTuple<Long, Long>> changedGroups) {
    checkNotNull(changedGroups);
    if (membershipChangeSchedule == null) {
        String msg = "Cannot apply CP membership changes: " + changedGroups + " since there is no membership change context!";
        logger.warning(msg);
        throw new IllegalStateException(msg);
    }
    for (CPGroupMembershipChange change : membershipChangeSchedule.getChanges()) {
        CPGroupId groupId = change.getGroupId();
        CPGroupInfo group = groups.get(groupId);
        checkState(group != null, groupId + "not found in CP groups: " + groups.keySet() + "to apply " + change);
        BiTuple<Long, Long> t = changedGroups.get(groupId);
        if (t != null) {
            if (!applyMembershipChange(change, group, t.element1, t.element2)) {
                changedGroups.remove(groupId);
            }
        } else if (group.status() == DESTROYED && !changedGroups.containsKey(groupId)) {
            if (logger.isFineEnabled()) {
                logger.warning(groupId + " is already destroyed so will skip: " + change);
            }
            changedGroups.put(groupId, BiTuple.of(0L, 0L));
        }
    }
    membershipChangeSchedule = membershipChangeSchedule.excludeCompletedChanges(changedGroups.keySet());
    if (checkSafeToRemoveIfCPMemberLeaving(membershipChangeSchedule)) {
        CPMemberInfo leavingMember = membershipChangeSchedule.getLeavingMember();
        removeActiveMember(commitIndex, leavingMember);
        completeFutures(getMetadataGroupId(), membershipChangeSchedule.getMembershipChangeCommitIndices(), null);
        membershipChangeSchedule = null;
        logger.info(leavingMember + " is removed from CP Subsystem.");
    } else if (membershipChangeSchedule.getChanges().isEmpty()) {
        completeFutures(getMetadataGroupId(), membershipChangeSchedule.getMembershipChangeCommitIndices(), null);
        membershipChangeSchedule = null;
        logger.info("Rebalancing is completed.");
    }
    return membershipChangeSchedule;
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroupMembershipChange(com.hazelcast.cp.internal.MembershipChangeSchedule.CPGroupMembershipChange)

Example 2 with CPGroupMembershipChange

use of com.hazelcast.cp.internal.MembershipChangeSchedule.CPGroupMembershipChange 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 3 with CPGroupMembershipChange

use of com.hazelcast.cp.internal.MembershipChangeSchedule.CPGroupMembershipChange in project hazelcast by hazelcast.

the class MetadataRaftGroupManager method getGroupMembershipChangesForNewMember.

private List<CPGroupMembershipChange> getGroupMembershipChangesForNewMember(CPMemberInfo newMember) {
    List<CPGroupMembershipChange> changes = new ArrayList<>();
    for (CPGroupInfo group : groups.values()) {
        if (group.status() == ACTIVE && group.initialMemberCount() > group.memberCount()) {
            checkState(!group.memberImpls().contains(newMember.toRaftEndpoint()), group + " already contains: " + newMember);
            changes.add(new CPGroupMembershipChange(group.id(), group.getMembersCommitIndex(), group.memberImpls(), newMember.toRaftEndpoint(), null));
        }
    }
    return changes;
}
Also used : ArrayList(java.util.ArrayList) CPGroupMembershipChange(com.hazelcast.cp.internal.MembershipChangeSchedule.CPGroupMembershipChange)

Aggregations

CPGroupMembershipChange (com.hazelcast.cp.internal.MembershipChangeSchedule.CPGroupMembershipChange)3 CPGroupId (com.hazelcast.cp.CPGroupId)2 ArrayList (java.util.ArrayList)2 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)1