Search in sources :

Example 6 with Replicate

use of org.opendaylight.controller.cluster.raft.base.messages.Replicate in project controller by opendaylight.

the class LeaderTest method sendReplicate.

private RaftActorBehavior sendReplicate(MockRaftActorContext actorContext, long term, long index, Payload payload) {
    SimpleReplicatedLogEntry newEntry = new SimpleReplicatedLogEntry(index, term, payload);
    actorContext.getReplicatedLog().append(newEntry);
    return leader.handleMessage(leaderActor, new Replicate(null, null, newEntry, true));
}
Also used : Replicate(org.opendaylight.controller.cluster.raft.base.messages.Replicate) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry)

Example 7 with Replicate

use of org.opendaylight.controller.cluster.raft.base.messages.Replicate in project controller by opendaylight.

the class LeaderTest method testInitiateInstallSnapshot.

@Test
public void testInitiateInstallSnapshot() throws Exception {
    logStart("testInitiateInstallSnapshot");
    MockRaftActorContext actorContext = createActorContextWithFollower();
    // clears leaders log
    actorContext.getReplicatedLog().removeFrom(0);
    final int followersLastIndex = 2;
    final int snapshotIndex = 3;
    final int newEntryIndex = 4;
    final int snapshotTerm = 1;
    final int currentTerm = 2;
    // set the snapshot variables in replicatedlog
    actorContext.getReplicatedLog().setSnapshotIndex(snapshotIndex);
    actorContext.getReplicatedLog().setSnapshotTerm(snapshotTerm);
    actorContext.setLastApplied(3);
    actorContext.setCommitIndex(followersLastIndex);
    leader = new Leader(actorContext);
    // Leader will send an immediate heartbeat - ignore it.
    MessageCollectorActor.expectFirstMatching(followerActor, AppendEntries.class);
    // set the snapshot as absent and check if capture-snapshot is invoked.
    leader.setSnapshotHolder(null);
    // new entry
    SimpleReplicatedLogEntry entry = new SimpleReplicatedLogEntry(newEntryIndex, currentTerm, new MockRaftActorContext.MockPayload("D"));
    actorContext.getReplicatedLog().append(entry);
    // update follower timestamp
    leader.markFollowerActive(FOLLOWER_ID);
    leader.handleMessage(leaderActor, new Replicate(null, new MockIdentifier("state-id"), entry, true));
    assertEquals("isCapturing", true, actorContext.getSnapshotManager().isCapturing());
    CaptureSnapshot cs = actorContext.getSnapshotManager().getCaptureSnapshot();
    assertEquals(3, cs.getLastAppliedIndex());
    assertEquals(1, cs.getLastAppliedTerm());
    assertEquals(4, cs.getLastIndex());
    assertEquals(2, cs.getLastTerm());
    // if an initiate is started again when first is in progress, it shouldnt initiate Capture
    leader.handleMessage(leaderActor, new Replicate(null, new MockIdentifier("state-id"), entry, true));
    assertSame("CaptureSnapshot instance", cs, actorContext.getSnapshotManager().getCaptureSnapshot());
}
Also used : Replicate(org.opendaylight.controller.cluster.raft.base.messages.Replicate) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) MockRaftActorContext(org.opendaylight.controller.cluster.raft.MockRaftActorContext) CaptureSnapshot(org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshot) Test(org.junit.Test)

Aggregations

Replicate (org.opendaylight.controller.cluster.raft.base.messages.Replicate)7 SimpleReplicatedLogEntry (org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry)6 Test (org.junit.Test)4 MockRaftActorContext (org.opendaylight.controller.cluster.raft.MockRaftActorContext)4 ApplyState (org.opendaylight.controller.cluster.raft.base.messages.ApplyState)2 CaptureSnapshot (org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshot)2 Optional (com.google.common.base.Optional)1 ByteString (com.google.protobuf.ByteString)1 HashMap (java.util.HashMap)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ReplicatedLogEntry (org.opendaylight.controller.cluster.raft.ReplicatedLogEntry)1 CheckConsensusReached (org.opendaylight.controller.cluster.raft.base.messages.CheckConsensusReached)1 SendHeartBeat (org.opendaylight.controller.cluster.raft.base.messages.SendHeartBeat)1 SendInstallSnapshot (org.opendaylight.controller.cluster.raft.base.messages.SendInstallSnapshot)1 AppendEntriesReply (org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply)1 InstallSnapshotReply (org.opendaylight.controller.cluster.raft.messages.InstallSnapshotReply)1 RaftRPC (org.opendaylight.controller.cluster.raft.messages.RaftRPC)1 RequestVote (org.opendaylight.controller.cluster.raft.messages.RequestVote)1 ApplyJournalEntries (org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntries)1 Identifier (org.opendaylight.yangtools.concepts.Identifier)1