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