Class SnapshotManager

  • All Implemented Interfaces:
    SnapshotState

    public class SnapshotManager
    extends Object
    implements SnapshotState
    Manages the capturing of snapshots for a RaftActor.
    Author:
    Moiz Raja, Thomas Pantelis
    • Constructor Detail

      • SnapshotManager

        public SnapshotManager​(RaftActorContext context,
                               Logger logger)
        Constructs an instance.
        Parameters:
        context - the RaftActorContext
        logger - the Logger
    • Method Detail

      • isApplying

        public boolean isApplying()
      • isCapturing

        public boolean isCapturing()
        Description copied from interface: SnapshotState
        Returns whether or not a capture is in progress.
        Specified by:
        isCapturing in interface SnapshotState
        Returns:
        true when a snapshot is being captured, false otherwise
      • captureToInstall

        public boolean captureToInstall​(ReplicatedLogEntry lastLogEntry,
                                        long replicatedToAllIndex,
                                        String targetFollower)
        Description copied from interface: SnapshotState
        Initiates a capture snapshot for the purposing of installing the snapshot on a follower.
        Specified by:
        captureToInstall in interface SnapshotState
        Parameters:
        lastLogEntry - the last entry in the replicated log
        replicatedToAllIndex - the current replicatedToAllIndex
        targetFollower - the id of the follower on which to install
        Returns:
        true if capture was started
      • capture

        public boolean capture​(ReplicatedLogEntry lastLogEntry,
                               long replicatedToAllIndex)
        Description copied from interface: SnapshotState
        Initiates a capture snapshot.
        Specified by:
        capture in interface SnapshotState
        Parameters:
        lastLogEntry - the last entry in the replicated log
        replicatedToAllIndex - the current replicatedToAllIndex
        Returns:
        true if capture was started
      • captureWithForcedTrim

        public boolean captureWithForcedTrim​(ReplicatedLogEntry lastLogEntry,
                                             long replicatedToAllIndex)
        Description copied from interface: SnapshotState
        Initiates a capture snapshot, while enforcing trimming of the log up to lastAppliedIndex.
        Specified by:
        captureWithForcedTrim in interface SnapshotState
        Parameters:
        lastLogEntry - the last entry in the replicated log
        replicatedToAllIndex - the current replicatedToAllIndex
        Returns:
        true if capture was started
      • apply

        public void apply​(ApplySnapshot snapshot)
        Description copied from interface: SnapshotState
        Applies a snapshot on a follower that was installed by the leader.
        Specified by:
        apply in interface SnapshotState
        Parameters:
        snapshot - the Snapshot to apply.
      • persist

        public void persist​(Snapshot.State state,
                            Optional<OutputStream> installSnapshotStream,
                            long totalMemory)
        Description copied from interface: SnapshotState
        Persists a snapshot.
        Specified by:
        persist in interface SnapshotState
        Parameters:
        state - the snapshot State
        installSnapshotStream - Optional OutputStream that is present if the snapshot is to also be installed on a follower.
        totalMemory - the total memory threshold
      • commit

        public void commit​(long sequenceNumber,
                           long timeStamp)
        Description copied from interface: SnapshotState
        Commit the snapshot by trimming the log.
        Specified by:
        commit in interface SnapshotState
        Parameters:
        sequenceNumber - the sequence number of the persisted snapshot
        timeStamp - the time stamp of the persisted snapshot
      • rollback

        public void rollback()
        Description copied from interface: SnapshotState
        Rolls back the snapshot on failure.
        Specified by:
        rollback in interface SnapshotState
      • trimLog

        public long trimLog​(long desiredTrimIndex)
        Description copied from interface: SnapshotState
        Trims the in-memory log.
        Specified by:
        trimLog in interface SnapshotState
        Parameters:
        desiredTrimIndex - the desired index to trim from
        Returns:
        the actual trim index
      • getLastSequenceNumber

        public long getLastSequenceNumber()
      • newCaptureSnapshot

        public CaptureSnapshot newCaptureSnapshot​(ReplicatedLogEntry lastLogEntry,
                                                  long replicatedToAllIndex,
                                                  boolean mandatoryTrim)
        Constructs a CaptureSnapshot instance.
        Parameters:
        lastLogEntry - the last log entry for the snapshot.
        replicatedToAllIndex - the index of the last entry replicated to all followers.
        Returns:
        a new CaptureSnapshot instance.