use of com.hazelcast.cp.exception.CPSubsystemException in project hazelcast by hazelcast.
the class AbstractAtomicRegisterSnapshotTest method test_snapshot.
@Test
public void test_snapshot() throws Exception {
T initialValue = setAndGetInitialValue();
// force snapshot
for (int i = 0; i < SNAPSHOT_THRESHOLD; i++) {
T v = readValue();
assertEquals(initialValue, v);
}
// shutdown the last instance
instances[instances.length - 1].shutdown();
HazelcastInstance instance = factory.newHazelcastInstance(createConfig(3, 3));
instance.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
// Read from local CP member, which should install snapshot after promotion.
assertTrueEventually(() -> {
InternalCompletableFuture<Object> future = queryLocally(instance);
try {
T value = getValue(future);
assertEquals(initialValue, value);
} catch (CPSubsystemException e) {
// Raft node may not be created yet...
throw new AssertionError(e);
}
});
assertTrueAllTheTime(() -> {
InternalCompletableFuture<Object> future = queryLocally(instance);
T value = getValue(future);
assertEquals(initialValue, value);
}, 5);
}
use of com.hazelcast.cp.exception.CPSubsystemException in project hazelcast by hazelcast.
the class ReplicateTask 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 (!raftNode.canReplicateNewEntry(operation)) {
resultFuture.completeExceptionally(new CannotReplicateException(raftNode.getLocalMember()));
return;
}
if (logger.isFineEnabled()) {
logger.fine("Replicating: " + operation + " in term: " + state.term());
}
RaftLog log = state.log();
if (!log.checkAvailableCapacity(1)) {
resultFuture.completeExceptionally(new IllegalStateException("Not enough capacity in RaftLog!"));
return;
}
long newEntryLogIndex = log.lastLogOrSnapshotIndex() + 1;
raftNode.registerFuture(newEntryLogIndex, resultFuture);
log.appendEntries(new LogEntry(state.term(), newEntryLogIndex, operation));
preApplyRaftGroupCmd(newEntryLogIndex, operation);
raftNode.broadcastAppendRequest();
} catch (Throwable t) {
logger.severe(operation + " could not be replicated to leader: " + raftNode.getLocalMember(), t);
RaftEndpoint leader = raftNode.getLeader();
UUID leaderUuid = leader != null ? leader.getUuid() : null;
resultFuture.completeExceptionally(new CPSubsystemException("Internal failure", t, leaderUuid));
}
}
use of com.hazelcast.cp.exception.CPSubsystemException 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