Search in sources :

Example 11 with FollowerInitialSyncUpStatus

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

the class SyncStatusTrackerTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    SyncStatusTracker tracker = new SyncStatusTracker(listener, "commit-tracker", 10);
    // When leader-1 sends the first update message the listener should receive a syncStatus notification
    // with status set to false
    tracker.update("leader-1", 100, 99);
    FollowerInitialSyncUpStatus status = MessageCollectorActor.getFirstMatching(listener, FollowerInitialSyncUpStatus.class);
    assertEquals(false, status.isInitialSyncDone());
    MessageCollectorActor.clearMessages(listener);
    // At a minimum the follower should have the commit index that the new leader sent it in the first message
    // Also the commit index must be below the syncThreshold. If both conditions are met a new sync status
    // message with status = true should be expected
    tracker.update("leader-1", 105, 101);
    status = MessageCollectorActor.getFirstMatching(listener, FollowerInitialSyncUpStatus.class);
    assertEquals(true, status.isInitialSyncDone());
    MessageCollectorActor.clearMessages(listener);
    // If a subsequent message is received and if the difference between the followers commit index and
    // the leaders commit index is below the syncThreshold then no status notification must be issues
    tracker.update("leader-1", 108, 101);
    status = MessageCollectorActor.getFirstMatching(listener, FollowerInitialSyncUpStatus.class);
    assertNull("No status message should be received", status);
    // If the follower falls behind the leader by more than the syncThreshold then the listener should
    // receive a syncStatus notification with status = false
    tracker.update("leader-1", 150, 101);
    status = MessageCollectorActor.getFirstMatching(listener, FollowerInitialSyncUpStatus.class);
    assertNotNull("No sync status message was received", status);
    assertEquals(false, status.isInitialSyncDone());
    MessageCollectorActor.clearMessages(listener);
    // If the follower is not caught up yet it should not receive any further notification
    tracker.update("leader-1", 150, 125);
    status = MessageCollectorActor.getFirstMatching(listener, FollowerInitialSyncUpStatus.class);
    assertNull("No status message should be received", status);
    // Once the syncThreshold is met a new syncStatus notification should be issued
    tracker.update("leader-1", 160, 155);
    status = MessageCollectorActor.getFirstMatching(listener, FollowerInitialSyncUpStatus.class);
    assertEquals(true, status.isInitialSyncDone());
    MessageCollectorActor.clearMessages(listener);
    // When a new leader starts sending update messages a new syncStatus notification should be immediately
    // triggered with status = false
    tracker.update("leader-2", 160, 155);
    status = MessageCollectorActor.getFirstMatching(listener, FollowerInitialSyncUpStatus.class);
    assertEquals(false, status.isInitialSyncDone());
    MessageCollectorActor.clearMessages(listener);
    // If an update is received from a new leader which is still below the minimum expected index then
    // syncStatus should not be changed
    tracker.update("leader-2", 160, 159);
    status = MessageCollectorActor.getFirstMatching(listener, FollowerInitialSyncUpStatus.class);
    assertNull("No status message should be received", status);
}
Also used : FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) AbstractActorTest(org.opendaylight.controller.cluster.raft.AbstractActorTest) Test(org.junit.Test)

Example 12 with FollowerInitialSyncUpStatus

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

the class FollowerTest method testHandleFirstAppendEntries.

@Test
public void testHandleFirstAppendEntries() {
    logStart("testHandleFirstAppendEntries");
    MockRaftActorContext context = createActorContext();
    context.getReplicatedLog().clear(0, 2);
    context.getReplicatedLog().append(newReplicatedLogEntry(1, 100, "bar"));
    context.getReplicatedLog().setSnapshotIndex(99);
    List<ReplicatedLogEntry> entries = Arrays.asList(newReplicatedLogEntry(2, 101, "foo"));
    Assert.assertEquals(1, context.getReplicatedLog().size());
    // The new commitIndex is 101
    AppendEntries appendEntries = new AppendEntries(2, "leader-1", 100, 1, entries, 101, 100, (short) 0);
    follower = createBehavior(context);
    follower.handleMessage(leaderActor, appendEntries);
    FollowerInitialSyncUpStatus syncStatus = MessageCollectorActor.expectFirstMatching(followerActor, FollowerInitialSyncUpStatus.class);
    AppendEntriesReply reply = MessageCollectorActor.expectFirstMatching(leaderActor, AppendEntriesReply.class);
    assertFalse(syncStatus.isInitialSyncDone());
    assertTrue("append entries reply should be true", reply.isSuccess());
}
Also used : SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) ReplicatedLogEntry(org.opendaylight.controller.cluster.raft.ReplicatedLogEntry) AppendEntriesReply(org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply) MockRaftActorContext(org.opendaylight.controller.cluster.raft.MockRaftActorContext) AppendEntries(org.opendaylight.controller.cluster.raft.messages.AppendEntries) FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) Test(org.junit.Test)

Example 13 with FollowerInitialSyncUpStatus

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

the class FollowerTest method testHandleFirstAppendEntriesWithPrevIndexMinusOneAndReplicatedToAllIndexPresentInSnapshot.

@Test
public void testHandleFirstAppendEntriesWithPrevIndexMinusOneAndReplicatedToAllIndexPresentInSnapshot() {
    logStart("testHandleFirstAppendEntries");
    MockRaftActorContext context = createActorContext();
    context.getReplicatedLog().clear(0, 2);
    context.getReplicatedLog().setSnapshotIndex(100);
    List<ReplicatedLogEntry> entries = Arrays.asList(newReplicatedLogEntry(2, 101, "foo"));
    // The new commitIndex is 101
    AppendEntries appendEntries = new AppendEntries(2, "leader-1", -1, -1, entries, 101, 100, (short) 0);
    follower = createBehavior(context);
    follower.handleMessage(leaderActor, appendEntries);
    FollowerInitialSyncUpStatus syncStatus = MessageCollectorActor.expectFirstMatching(followerActor, FollowerInitialSyncUpStatus.class);
    AppendEntriesReply reply = MessageCollectorActor.expectFirstMatching(leaderActor, AppendEntriesReply.class);
    assertFalse(syncStatus.isInitialSyncDone());
    assertTrue("append entries reply should be true", reply.isSuccess());
}
Also used : SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) ReplicatedLogEntry(org.opendaylight.controller.cluster.raft.ReplicatedLogEntry) AppendEntriesReply(org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply) MockRaftActorContext(org.opendaylight.controller.cluster.raft.MockRaftActorContext) AppendEntries(org.opendaylight.controller.cluster.raft.messages.AppendEntries) FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) Test(org.junit.Test)

Example 14 with FollowerInitialSyncUpStatus

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

the class SyncStatusTracker method changeSyncStatus.

private void changeSyncStatus(final boolean newSyncStatus, final boolean forceStatusChange) {
    if (forceStatusChange || newSyncStatus != syncStatus) {
        actor.tell(new FollowerInitialSyncUpStatus(newSyncStatus, id), ActorRef.noSender());
        syncStatus = newSyncStatus;
    } else {
        LOG.trace("{}: No change in sync status of, dampening message", id);
    }
}
Also used : FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus)

Example 15 with FollowerInitialSyncUpStatus

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

the class ShardManagerTest method testWhenMultipleShardsPresentSyncStatusMustBeTrueForAllShards.

@Test
public void testWhenMultipleShardsPresentSyncStatusMustBeTrueForAllShards() throws Exception {
    LOG.info("testWhenMultipleShardsPresentSyncStatusMustBeTrueForAllShards starting");
    TestShardManager shardManager = newTestShardManager(newShardMgrProps(new MockConfiguration() {

        @Override
        public List<String> getMemberShardNames(final MemberName memberName) {
            return Arrays.asList("default", "astronauts");
        }
    }));
    // Initially will be false
    assertEquals(false, shardManager.getMBean().getSyncStatus());
    // Make default shard leader
    String defaultShardId = "member-1-shard-default-" + shardMrgIDSuffix;
    shardManager.onReceiveCommand(new RoleChangeNotification(defaultShardId, RaftState.Follower.name(), RaftState.Leader.name()));
    // default = Leader, astronauts is unknown so sync status remains false
    assertEquals(false, shardManager.getMBean().getSyncStatus());
    // Make astronauts shard leader as well
    String astronautsShardId = "member-1-shard-astronauts-" + shardMrgIDSuffix;
    shardManager.onReceiveCommand(new RoleChangeNotification(astronautsShardId, RaftState.Follower.name(), RaftState.Leader.name()));
    // Now sync status should be true
    assertEquals(true, shardManager.getMBean().getSyncStatus());
    // Make astronauts a Follower
    shardManager.onReceiveCommand(new RoleChangeNotification(astronautsShardId, RaftState.Leader.name(), RaftState.Follower.name()));
    // Sync status is not true
    assertEquals(false, shardManager.getMBean().getSyncStatus());
    // Make the astronauts follower sync status true
    shardManager.onReceiveCommand(new FollowerInitialSyncUpStatus(true, astronautsShardId));
    // Sync status is now true
    assertEquals(true, shardManager.getMBean().getSyncStatus());
    LOG.info("testWhenMultipleShardsPresentSyncStatusMustBeTrueForAllShards ending");
}
Also used : RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) AddressFromURIString(akka.actor.AddressFromURIString) FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Aggregations

FollowerInitialSyncUpStatus (org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus)16 Test (org.junit.Test)14 MockRaftActorContext (org.opendaylight.controller.cluster.raft.MockRaftActorContext)9 ReplicatedLogEntry (org.opendaylight.controller.cluster.raft.ReplicatedLogEntry)9 AppendEntries (org.opendaylight.controller.cluster.raft.messages.AppendEntries)9 SimpleReplicatedLogEntry (org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry)9 AppendEntriesReply (org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply)5 AddressFromURIString (akka.actor.AddressFromURIString)3 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)3 RoleChangeNotification (org.opendaylight.controller.cluster.notifications.RoleChangeNotification)3 ByteString (com.google.protobuf.ByteString)1 ConnectClientRequest (org.opendaylight.controller.cluster.access.commands.ConnectClientRequest)1 MemberName (org.opendaylight.controller.cluster.access.concepts.MemberName)1 RequestEnvelope (org.opendaylight.controller.cluster.access.concepts.RequestEnvelope)1 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)1 MessageTracker (org.opendaylight.controller.cluster.common.actor.MessageTracker)1 Error (org.opendaylight.controller.cluster.common.actor.MessageTracker.Error)1 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)1 ForwardedReadyTransaction (org.opendaylight.controller.cluster.datastore.messages.ForwardedReadyTransaction)1 GetShardDataTree (org.opendaylight.controller.cluster.datastore.messages.GetShardDataTree)1