use of org.opendaylight.controller.cluster.raft.base.messages.InitiateCaptureSnapshot in project controller by opendaylight.
the class RaftActorServerConfigurationSupportTest method testAddServerWithLeaderChangeBeforePriorSnapshotComplete.
@Test
public void testAddServerWithLeaderChangeBeforePriorSnapshotComplete() throws Exception {
LOG.info("testAddServerWithLeaderChangeBeforePriorSnapshotComplete starting");
setupNewFollower();
RaftActorContext initialActorContext = new MockRaftActorContext();
TestActorRef<MockLeaderRaftActor> leaderActor = actorFactory.createTestActor(MockLeaderRaftActor.props(ImmutableMap.<String, String>of(), initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID));
MockLeaderRaftActor leaderRaftActor = leaderActor.underlyingActor();
RaftActorContext leaderActorContext = leaderRaftActor.getRaftActorContext();
((DefaultConfigParamsImpl) leaderActorContext.getConfigParams()).setElectionTimeoutFactor(100);
final ActorRef leaderCollectorActor = newLeaderCollectorActor(leaderRaftActor);
// Drop the commit message so the snapshot doesn't complete yet.
leaderRaftActor.setDropMessageOfType(COMMIT_MESSAGE_CLASS);
leaderActor.tell(new InitiateCaptureSnapshot(), leaderActor);
leaderActor.tell(new AddServer(NEW_SERVER_ID, newFollowerRaftActor.path().toString(), true), testKit.getRef());
Object commitMsg = expectFirstMatching(leaderCollectorActor, COMMIT_MESSAGE_CLASS);
// Change the leader behavior to follower
leaderActor.tell(new Follower(leaderActorContext), leaderActor);
// Drop CaptureSnapshotReply in case install snapshot is incorrectly initiated after the prior
// snapshot completes. This will prevent the invalid snapshot from completing and fail the
// isCapturing assertion below.
leaderRaftActor.setDropMessageOfType(CaptureSnapshotReply.class);
// Complete the prior snapshot - this should be a no-op b/c it's no longer the leader
leaderActor.tell(commitMsg, leaderActor);
leaderActor.tell(new RaftActorServerConfigurationSupport.ServerOperationTimeout(NEW_SERVER_ID), leaderActor);
AddServerReply addServerReply = testKit.expectMsgClass(testKit.duration("5 seconds"), AddServerReply.class);
assertEquals("getStatus", ServerChangeStatus.NO_LEADER, addServerReply.getStatus());
assertEquals("Leader peers size", 0, leaderActorContext.getPeerIds().size());
assertEquals("isCapturing", false, leaderActorContext.getSnapshotManager().isCapturing());
LOG.info("testAddServerWithLeaderChangeBeforePriorSnapshotComplete ending");
}
use of org.opendaylight.controller.cluster.raft.base.messages.InitiateCaptureSnapshot in project controller by opendaylight.
the class RaftActorServerConfigurationSupportTest method testAddServerWithPriorSnapshotCompleteTimeout.
@Test
public void testAddServerWithPriorSnapshotCompleteTimeout() throws Exception {
LOG.info("testAddServerWithPriorSnapshotCompleteTimeout starting");
setupNewFollower();
RaftActorContext initialActorContext = new MockRaftActorContext();
TestActorRef<MockLeaderRaftActor> leaderActor = actorFactory.createTestActor(MockLeaderRaftActor.props(ImmutableMap.<String, String>of(), initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID));
MockLeaderRaftActor leaderRaftActor = leaderActor.underlyingActor();
RaftActorContext leaderActorContext = leaderRaftActor.getRaftActorContext();
((DefaultConfigParamsImpl) leaderActorContext.getConfigParams()).setElectionTimeoutFactor(1);
// Drop commit message so the snapshot doesn't complete.
leaderRaftActor.setDropMessageOfType(COMMIT_MESSAGE_CLASS);
leaderActor.tell(new InitiateCaptureSnapshot(), leaderActor);
leaderActor.tell(new AddServer(NEW_SERVER_ID, newFollowerRaftActor.path().toString(), true), testKit.getRef());
AddServerReply addServerReply = testKit.expectMsgClass(testKit.duration("5 seconds"), AddServerReply.class);
assertEquals("getStatus", ServerChangeStatus.TIMEOUT, addServerReply.getStatus());
assertEquals("Leader peers size", 0, leaderActorContext.getPeerIds().size());
LOG.info("testAddServerWithPriorSnapshotCompleteTimeout ending");
}
use of org.opendaylight.controller.cluster.raft.base.messages.InitiateCaptureSnapshot in project controller by opendaylight.
the class RaftActorServerConfigurationSupportTest method testAddServerWithPriorSnapshotInProgress.
@Test
public void testAddServerWithPriorSnapshotInProgress() throws Exception {
LOG.info("testAddServerWithPriorSnapshotInProgress starting");
setupNewFollower();
RaftActorContext initialActorContext = new MockRaftActorContext();
TestActorRef<MockLeaderRaftActor> leaderActor = actorFactory.createTestActor(MockLeaderRaftActor.props(ImmutableMap.<String, String>of(), initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID));
MockLeaderRaftActor leaderRaftActor = leaderActor.underlyingActor();
final RaftActorContext leaderActorContext = leaderRaftActor.getRaftActorContext();
ActorRef leaderCollectorActor = newLeaderCollectorActor(leaderRaftActor);
// Drop commit message for now to delay snapshot completion
leaderRaftActor.setDropMessageOfType(String.class);
leaderActor.tell(new InitiateCaptureSnapshot(), leaderActor);
Object commitMsg = expectFirstMatching(leaderCollectorActor, COMMIT_MESSAGE_CLASS);
leaderActor.tell(new AddServer(NEW_SERVER_ID, newFollowerRaftActor.path().toString(), true), testKit.getRef());
leaderRaftActor.setDropMessageOfType(null);
leaderActor.tell(commitMsg, leaderActor);
AddServerReply addServerReply = testKit.expectMsgClass(testKit.duration("5 seconds"), AddServerReply.class);
assertEquals("getStatus", ServerChangeStatus.OK, addServerReply.getStatus());
assertEquals("getLeaderHint", LEADER_ID, addServerReply.getLeaderHint().get());
expectFirstMatching(newFollowerCollectorActor, ApplySnapshot.class);
// Verify ServerConfigurationPayload entry in leader's log
expectFirstMatching(leaderCollectorActor, ApplyState.class);
assertEquals("Leader journal last index", 0, leaderActorContext.getReplicatedLog().lastIndex());
assertEquals("Leader commit index", 0, leaderActorContext.getCommitIndex());
assertEquals("Leader last applied index", 0, leaderActorContext.getLastApplied());
verifyServerConfigurationPayloadEntry(leaderActorContext.getReplicatedLog(), votingServer(LEADER_ID), votingServer(NEW_SERVER_ID));
LOG.info("testAddServerWithPriorSnapshotInProgress ending");
}
use of org.opendaylight.controller.cluster.raft.base.messages.InitiateCaptureSnapshot in project controller by opendaylight.
the class RaftActor method handleCommand.
/**
* Handles a message.
*
* @deprecated This method is not final for testing purposes. DO NOT OVERRIDE IT, override
* {@link #handleNonRaftCommand(Object)} instead.
*/
@Deprecated
@Override
protected // FIXME: make this method final once our unit tests do not need to override it
void handleCommand(final Object message) {
if (serverConfigurationSupport.handleMessage(message, getSender())) {
return;
}
if (snapshotSupport.handleSnapshotMessage(message, getSender())) {
return;
}
if (message instanceof ApplyState) {
ApplyState applyState = (ApplyState) message;
if (!hasFollowers()) {
// for single node, the capture should happen after the apply state
// as we delete messages from the persistent journal which have made it to the snapshot
// capturing the snapshot before applying makes the persistent journal and snapshot out of sync
// and recovery shows data missing
context.getReplicatedLog().captureSnapshotIfReady(applyState.getReplicatedLogEntry());
context.getSnapshotManager().trimLog(context.getLastApplied());
}
possiblyHandleBehaviorMessage(message);
} else if (message instanceof ApplyJournalEntries) {
ApplyJournalEntries applyEntries = (ApplyJournalEntries) message;
LOG.debug("{}: Persisting ApplyJournalEntries with index={}", persistenceId(), applyEntries.getToIndex());
persistence().persistAsync(applyEntries, NoopProcedure.instance());
} else if (message instanceof FindLeader) {
getSender().tell(new FindLeaderReply(getLeaderAddress()), getSelf());
} else if (message instanceof GetOnDemandRaftState) {
onGetOnDemandRaftStats();
} else if (message instanceof InitiateCaptureSnapshot) {
captureSnapshot();
} else if (message instanceof SwitchBehavior) {
switchBehavior((SwitchBehavior) message);
} else if (message instanceof LeaderTransitioning) {
onLeaderTransitioning((LeaderTransitioning) message);
} else if (message instanceof Shutdown) {
onShutDown();
} else if (message instanceof Runnable) {
((Runnable) message).run();
} else if (message instanceof NoopPayload) {
persistData(null, null, (NoopPayload) message, false);
} else if (message instanceof RequestLeadership) {
onRequestLeadership((RequestLeadership) message);
} else if (!possiblyHandleBehaviorMessage(message)) {
handleNonRaftCommand(message);
}
}
Aggregations