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 TypeMethodDescriptionvoidapply(ApplySnapshot snapshot) Applies a snapshot on a follower that was installed by the leader.booleancapture(RaftEntryMeta lastLogEntry, long replicatedToAllIndex) Initiates a capture snapshot.booleancaptureToInstall(RaftEntryMeta lastLogEntry, long replicatedToAllIndex, String targetFollower) Initiates a capture snapshot for the purposing of installing the snapshot on a follower.booleancaptureWithForcedTrim(RaftEntryMeta lastLogEntry, long replicatedToAllIndex) Initiates a capture snapshot, while enforcing trimming of the log up to lastAppliedIndex.voidcommit(long sequenceNumber, long timeStamp) Commit the snapshot by trimming the log.@NonNull Snapshot.StateconvertSnapshot(ByteSource snapshotBytes) longbooleanbooleanReturns whether or not a capture is in progress.newCaptureSnapshot(RaftEntryMeta lastLogEntry, long replicatedToAllIndex, boolean mandatoryTrim) Constructs a CaptureSnapshot instance.voidpersist(Snapshot.State state, Optional<OutputStream> installSnapshotStream, long totalMemory) Persists a snapshot.voidrollback()Rolls back the snapshot on failure.longtrimLog(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:SnapshotStateReturns whether or not a capture is in progress.- Specified by:
isCapturingin 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:SnapshotStateInitiates a capture snapshot for the purposing of installing the snapshot on a follower.- Specified by:
captureToInstallin 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:SnapshotStateInitiates a capture snapshot.- Specified by:
capturein interfaceSnapshotState- Parameters:
lastLogEntry- the last entry in the replicated logreplicatedToAllIndex- the current replicatedToAllIndex- Returns:
- true if capture was started
-
captureWithForcedTrim
Description copied from interface:SnapshotStateInitiates a capture snapshot, while enforcing trimming of the log up to lastAppliedIndex.- Specified by:
captureWithForcedTrimin interfaceSnapshotState- Parameters:
lastLogEntry- the last entry in the replicated logreplicatedToAllIndex- the current replicatedToAllIndex- Returns:
- true if capture was started
-
apply
Description copied from interface:SnapshotStateApplies a snapshot on a follower that was installed by the leader.- Specified by:
applyin interfaceSnapshotState- Parameters:
snapshot- the Snapshot to apply.
-
persist
public void persist(Snapshot.State state, Optional<OutputStream> installSnapshotStream, long totalMemory) Description copied from interface:SnapshotStatePersists a snapshot.- Specified by:
persistin 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:SnapshotStateCommit the snapshot by trimming the log.- Specified by:
commitin 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:SnapshotStateRolls back the snapshot on failure.- Specified by:
rollbackin interfaceSnapshotState
-
trimLog
public long trimLog(long desiredTrimIndex) Description copied from interface:SnapshotStateTrims the in-memory log.- Specified by:
trimLogin 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.
-