use of com.hazelcast.cp.internal.raft.command.DestroyRaftGroupCmd in project hazelcast by hazelcast.
the class RaftNodeImpl method applyRestoredRaftGroupCommands.
private void applyRestoredRaftGroupCommands(SnapshotEntry snapshot) {
// If there is a single Raft group command after the last snapshot,
// here we cannot know if the that command is committed or not so we
// just "pre-apply" that command without committing it.
// If there are multiple Raft group commands, it is definitely known
// that all the command up to the last command are committed,
// but the last command may not be committed.
// This conclusion boils down to the fact that once you append a Raft
// group command, you cannot append a new one before committing it.
RaftLog log = state.log();
LogEntry committedEntry = null;
LogEntry lastAppliedEntry = null;
for (long i = snapshot != null ? snapshot.index() + 1 : 1; i <= log.lastLogOrSnapshotIndex(); i++) {
LogEntry entry = log.getLogEntry(i);
assert entry != null : "index: " + i;
if (entry.operation() instanceof RaftGroupCmd) {
committedEntry = lastAppliedEntry;
lastAppliedEntry = entry;
}
}
if (committedEntry != null) {
state.commitIndex(committedEntry.index());
applyLogEntries();
}
if (lastAppliedEntry != null) {
if (lastAppliedEntry.operation() instanceof UpdateRaftGroupMembersCmd) {
setStatus(UPDATING_GROUP_MEMBER_LIST);
Collection<RaftEndpoint> members = ((UpdateRaftGroupMembersCmd) lastAppliedEntry.operation()).getMembers();
updateGroupMembers(lastAppliedEntry.index(), members);
} else if (lastAppliedEntry.operation() instanceof DestroyRaftGroupCmd) {
setStatus(TERMINATING);
} else {
throw new IllegalStateException("Invalid group command for restore: " + lastAppliedEntry);
}
}
}
use of com.hazelcast.cp.internal.raft.command.DestroyRaftGroupCmd in project hazelcast by hazelcast.
the class DestroyRaftGroupTest method when_destroyOpIsAppended_then_statusIsTerminating.
@Test
public void when_destroyOpIsAppended_then_statusIsTerminating() {
group = newGroup(2);
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
RaftNodeImpl follower = group.getAnyFollowerNode();
group.dropAllMessagesToMember(follower.getLocalMember(), leader.getLocalMember());
leader.replicate(new DestroyRaftGroupCmd());
assertTrueEventually(() -> {
assertEquals(RaftNodeStatus.TERMINATING, getStatus(leader));
assertEquals(RaftNodeStatus.TERMINATING, getStatus(follower));
});
}
use of com.hazelcast.cp.internal.raft.command.DestroyRaftGroupCmd in project hazelcast by hazelcast.
the class DestroyRaftGroupTest method when_destroyOpIsTruncated_then_statusIsActive.
@Test
public void when_destroyOpIsTruncated_then_statusIsActive() throws ExecutionException, InterruptedException {
group = newGroup(3);
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
group.dropMessagesToAll(leader.getLocalMember(), AppendRequest.class);
leader.replicate(new DestroyRaftGroupCmd());
group.split(leader.getLocalMember());
assertTrueEventually(() -> {
for (RaftNodeImpl raftNode : followers) {
RaftEndpoint leaderEndpoint = getLeaderMember(raftNode);
assertNotNull(leaderEndpoint);
assertNotEquals(leader.getLocalMember(), leaderEndpoint);
}
});
RaftNodeImpl newLeader = group.getNode(getLeaderMember(followers[0]));
for (int i = 0; i < 10; i++) {
newLeader.replicate(new ApplyRaftRunnable("val" + i)).get();
}
group.merge();
assertTrueEventually(() -> {
for (RaftNodeImpl raftNode : group.getNodes()) {
assertEquals(RaftNodeStatus.ACTIVE, getStatus(raftNode));
}
});
}
use of com.hazelcast.cp.internal.raft.command.DestroyRaftGroupCmd in project hazelcast by hazelcast.
the class DestroyRaftGroupTest method when_destroyOpIsAppendedButNotCommitted_then_cannotAppendNewEntry.
@Test
public void when_destroyOpIsAppendedButNotCommitted_then_cannotAppendNewEntry() throws ExecutionException, InterruptedException {
group = newGroup(2);
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
RaftNodeImpl follower = group.getAnyFollowerNode();
group.dropAllMessagesToMember(leader.getLocalMember(), follower.getLocalMember());
leader.replicate(new DestroyRaftGroupCmd());
try {
leader.replicate(new ApplyRaftRunnable("val")).joinInternal();
fail();
} catch (CannotReplicateException ignored) {
}
}
Aggregations