Search in sources :

Example 16 with FollowerLogInformation

use of org.opendaylight.controller.cluster.raft.FollowerLogInformation in project controller by opendaylight.

the class AbstractLeader method initiateCaptureSnapshot.

/**
 * Initiates a snapshot capture to install on a follower.
 *
 * <p>
 * Install Snapshot works as follows
 *   1. Leader initiates the capture snapshot by calling createSnapshot on the RaftActor.
 *   2. On receipt of the CaptureSnapshotReply message, the RaftActor persists the snapshot and makes a call to
 *      the Leader's handleMessage with a SendInstallSnapshot message.
 *   3. The Leader obtains and stores the Snapshot from the SendInstallSnapshot message and sends it in chunks to
 *      the Follower via InstallSnapshot messages.
 *   4. For each chunk, the Follower sends back an InstallSnapshotReply.
 *   5. On receipt of the InstallSnapshotReply for the last chunk, the Leader marks the install complete for that
 *      follower.
 *   6. If another follower requires a snapshot and a snapshot has been collected (via SendInstallSnapshot)
 *      then send the existing snapshot in chunks to the follower.
 *
 * @param followerId the id of the follower.
 * @return true if capture was initiated, false otherwise.
 */
public boolean initiateCaptureSnapshot(final String followerId) {
    FollowerLogInformation followerLogInfo = followerToLog.get(followerId);
    if (snapshotHolder.isPresent()) {
        // If a snapshot is present in the memory, most likely another install is in progress no need to capture
        // snapshot. This could happen if another follower needs an install when one is going on.
        final ActorSelection followerActor = context.getPeerActorSelection(followerId);
        // Note: sendSnapshotChunk will set the LeaderInstallSnapshotState.
        sendSnapshotChunk(followerActor, followerLogInfo);
        return true;
    }
    boolean captureInitiated = context.getSnapshotManager().captureToInstall(context.getReplicatedLog().last(), this.getReplicatedToAllIndex(), followerId);
    if (captureInitiated) {
        followerLogInfo.setLeaderInstallSnapshotState(new LeaderInstallSnapshotState(context.getConfigParams().getSnapshotChunkSize(), logName()));
    }
    return captureInitiated;
}
Also used : FollowerLogInformation(org.opendaylight.controller.cluster.raft.FollowerLogInformation) ActorSelection(akka.actor.ActorSelection)

Aggregations

FollowerLogInformation (org.opendaylight.controller.cluster.raft.FollowerLogInformation)16 Test (org.junit.Test)6 MockRaftActorContext (org.opendaylight.controller.cluster.raft.MockRaftActorContext)6 ReplicatedLogEntry (org.opendaylight.controller.cluster.raft.ReplicatedLogEntry)5 AppendEntriesReply (org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply)5 ActorSelection (akka.actor.ActorSelection)4 DefaultConfigParamsImpl (org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl)4 ApplyState (org.opendaylight.controller.cluster.raft.base.messages.ApplyState)4 AppendEntries (org.opendaylight.controller.cluster.raft.messages.AppendEntries)4 SimpleReplicatedLogEntry (org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry)4 FiniteDuration (scala.concurrent.duration.FiniteDuration)4 ByteString (com.google.protobuf.ByteString)1 HashMap (java.util.HashMap)1 PeerInfo (org.opendaylight.controller.cluster.raft.PeerInfo)1 SnapshotHolder (org.opendaylight.controller.cluster.raft.behaviors.AbstractLeader.SnapshotHolder)1 InstallSnapshotReply (org.opendaylight.controller.cluster.raft.messages.InstallSnapshotReply)1 UnInitializedFollowerSnapshotReply (org.opendaylight.controller.cluster.raft.messages.UnInitializedFollowerSnapshotReply)1 ApplyJournalEntries (org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntries)1