use of com.hazelcast.cp.internal.raft.exception.MemberAlreadyExistsException in project hazelcast by hazelcast.
the class MembershipChangeTask method run.
@Override
public void run() {
try {
if (!verifyRaftNodeStatus()) {
return;
}
RaftState state = raftNode.state();
if (state.role() != LEADER) {
resultFuture.completeExceptionally(new NotLeaderException(raftNode.getGroupId(), raftNode.getLocalMember(), state.leader()));
return;
}
if (!isValidGroupMemberCommitIndex()) {
return;
}
Collection<RaftEndpoint> members = new LinkedHashSet<RaftEndpoint>(state.members());
boolean memberExists = members.contains(member);
switch(membershipChangeMode) {
case ADD:
if (memberExists) {
resultFuture.completeExceptionally(new MemberAlreadyExistsException(member));
return;
}
members.add(member);
break;
case REMOVE:
if (!memberExists) {
resultFuture.completeExceptionally(new MemberDoesNotExistException(member));
return;
}
members.remove(member);
break;
default:
resultFuture.completeExceptionally(new IllegalArgumentException("Unknown type: " + membershipChangeMode));
return;
}
logger.info("New members after " + membershipChangeMode + " " + member + " -> " + members);
new ReplicateTask(raftNode, new UpdateRaftGroupMembersCmd(members, member, membershipChangeMode), resultFuture).run();
} catch (Throwable t) {
logger.severe(this + " failed", t);
RaftEndpoint leader = raftNode.getLeader();
UUID leaderUuid = leader != null ? leader.getUuid() : null;
resultFuture.completeExceptionally(new CPSubsystemException("Internal failure", t, leaderUuid));
}
}
Aggregations