Class SnapshotManager
java.lang.Object
org.opendaylight.controller.cluster.raft.SnapshotManager
- All Implemented Interfaces:
SnapshotState
Manages the capturing of snapshots for a RaftActor.
- Author:
- Moiz Raja, Thomas Pantelis
-
Constructor Summary
ConstructorsConstructorDescriptionSnapshotManager
(RaftActorContext context, Logger logger) Constructs an instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
apply
(ApplySnapshot snapshot) Applies a snapshot on a follower that was installed by the leader.boolean
capture
(RaftEntryMeta lastLogEntry, long replicatedToAllIndex) Initiates a capture snapshot.boolean
captureToInstall
(RaftEntryMeta lastLogEntry, long replicatedToAllIndex, String targetFollower) Initiates a capture snapshot for the purposing of installing the snapshot on a follower.boolean
captureWithForcedTrim
(RaftEntryMeta lastLogEntry, long replicatedToAllIndex) Initiates a capture snapshot, while enforcing trimming of the log up to lastAppliedIndex.void
commit
(long sequenceNumber, long timeStamp) Commit the snapshot by trimming the log.@NonNull Snapshot.State
convertSnapshot
(ByteSource snapshotBytes) long
boolean
boolean
Returns whether or not a capture is in progress.newCaptureSnapshot
(RaftEntryMeta lastLogEntry, long replicatedToAllIndex, boolean mandatoryTrim) Constructs a CaptureSnapshot instance.void
persist
(Snapshot.State state, Optional<OutputStream> installSnapshotStream, long totalMemory) Persists a snapshot.void
rollback()
Rolls back the snapshot on failure.long
trimLog
(long desiredTrimIndex) Trims the in-memory log.
-
Constructor Details
-
SnapshotManager
Constructs an instance.- Parameters:
context
- the RaftActorContextlogger
- the Logger
-
-
Method Details
-
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 interfaceSnapshotState
- Returns:
- true when a snapshot is being captured, false otherwise
-
captureToInstall
public boolean captureToInstall(RaftEntryMeta 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 interfaceSnapshotState
- Parameters:
lastLogEntry
- the last entry in the replicated logreplicatedToAllIndex
- the current replicatedToAllIndextargetFollower
- the id of the follower on which to install- Returns:
- true if capture was started
-
capture
Description copied from interface:SnapshotState
Initiates a capture snapshot.- Specified by:
capture
in interfaceSnapshotState
- Parameters:
lastLogEntry
- the last entry in the replicated logreplicatedToAllIndex
- the current replicatedToAllIndex- Returns:
- true if capture was started
-
captureWithForcedTrim
Description copied from interface:SnapshotState
Initiates a capture snapshot, while enforcing trimming of the log up to lastAppliedIndex.- Specified by:
captureWithForcedTrim
in interfaceSnapshotState
- Parameters:
lastLogEntry
- the last entry in the replicated logreplicatedToAllIndex
- the current replicatedToAllIndex- Returns:
- true if capture was started
-
apply
Description copied from interface:SnapshotState
Applies a snapshot on a follower that was installed by the leader.- Specified by:
apply
in interfaceSnapshotState
- 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 interfaceSnapshotState
- Parameters:
state
- the snapshot StateinstallSnapshotStream
- 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 interfaceSnapshotState
- Parameters:
sequenceNumber
- the sequence number of the persisted snapshottimeStamp
- 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 interfaceSnapshotState
-
trimLog
public long trimLog(long desiredTrimIndex) Description copied from interface:SnapshotState
Trims the in-memory log.- Specified by:
trimLog
in interfaceSnapshotState
- Parameters:
desiredTrimIndex
- the desired index to trim from- Returns:
- the actual trim index
-
convertSnapshot
- Throws:
IOException
-
getLastSequenceNumber
public long getLastSequenceNumber() -
getCaptureSnapshot
-
newCaptureSnapshot
public CaptureSnapshot newCaptureSnapshot(RaftEntryMeta 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.
-