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