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;
}
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;
}
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;
}
Aggregations