Search in sources :

Example 1 with InitiateCaptureSnapshot

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");
}
Also used : InitiateCaptureSnapshot(org.opendaylight.controller.cluster.raft.base.messages.InitiateCaptureSnapshot) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) Follower(org.opendaylight.controller.cluster.raft.behaviors.Follower) AddServer(org.opendaylight.controller.cluster.raft.messages.AddServer) AddServerReply(org.opendaylight.controller.cluster.raft.messages.AddServerReply) Test(org.junit.Test)

Example 2 with InitiateCaptureSnapshot

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");
}
Also used : InitiateCaptureSnapshot(org.opendaylight.controller.cluster.raft.base.messages.InitiateCaptureSnapshot) AddServerReply(org.opendaylight.controller.cluster.raft.messages.AddServerReply) AddServer(org.opendaylight.controller.cluster.raft.messages.AddServer) Test(org.junit.Test)

Example 3 with InitiateCaptureSnapshot

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");
}
Also used : InitiateCaptureSnapshot(org.opendaylight.controller.cluster.raft.base.messages.InitiateCaptureSnapshot) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) AddServerReply(org.opendaylight.controller.cluster.raft.messages.AddServerReply) AddServer(org.opendaylight.controller.cluster.raft.messages.AddServer) Test(org.junit.Test)

Example 4 with InitiateCaptureSnapshot

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);
    }
}
Also used : InitiateCaptureSnapshot(org.opendaylight.controller.cluster.raft.base.messages.InitiateCaptureSnapshot) FindLeaderReply(org.opendaylight.controller.cluster.raft.client.messages.FindLeaderReply) Shutdown(org.opendaylight.controller.cluster.raft.client.messages.Shutdown) RequestLeadership(org.opendaylight.controller.cluster.raft.messages.RequestLeadership) FindLeader(org.opendaylight.controller.cluster.raft.client.messages.FindLeader) NoopPayload(org.opendaylight.controller.cluster.raft.persisted.NoopPayload) ApplyJournalEntries(org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntries) GetOnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.GetOnDemandRaftState) LeaderTransitioning(org.opendaylight.controller.cluster.raft.base.messages.LeaderTransitioning) SwitchBehavior(org.opendaylight.controller.cluster.raft.base.messages.SwitchBehavior) ApplyState(org.opendaylight.controller.cluster.raft.base.messages.ApplyState)

Aggregations

InitiateCaptureSnapshot (org.opendaylight.controller.cluster.raft.base.messages.InitiateCaptureSnapshot)4 Test (org.junit.Test)3 AddServer (org.opendaylight.controller.cluster.raft.messages.AddServer)3 AddServerReply (org.opendaylight.controller.cluster.raft.messages.AddServerReply)3 ActorRef (akka.actor.ActorRef)2 TestActorRef (akka.testkit.TestActorRef)2 ApplyState (org.opendaylight.controller.cluster.raft.base.messages.ApplyState)1 LeaderTransitioning (org.opendaylight.controller.cluster.raft.base.messages.LeaderTransitioning)1 SwitchBehavior (org.opendaylight.controller.cluster.raft.base.messages.SwitchBehavior)1 Follower (org.opendaylight.controller.cluster.raft.behaviors.Follower)1 FindLeader (org.opendaylight.controller.cluster.raft.client.messages.FindLeader)1 FindLeaderReply (org.opendaylight.controller.cluster.raft.client.messages.FindLeaderReply)1 GetOnDemandRaftState (org.opendaylight.controller.cluster.raft.client.messages.GetOnDemandRaftState)1 Shutdown (org.opendaylight.controller.cluster.raft.client.messages.Shutdown)1 RequestLeadership (org.opendaylight.controller.cluster.raft.messages.RequestLeadership)1 ApplyJournalEntries (org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntries)1 NoopPayload (org.opendaylight.controller.cluster.raft.persisted.NoopPayload)1