Class SnapshotManager
- java.lang.Object
-
- org.opendaylight.controller.cluster.raft.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 Summary
Constructors Constructor Description SnapshotManager(RaftActorContext context, Logger logger)Constructs an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapply(ApplySnapshot snapshot)Applies a snapshot on a follower that was installed by the leader.booleancapture(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex)Initiates a capture snapshot.booleancaptureToInstall(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex, String targetFollower)Initiates a capture snapshot for the purposing of installing the snapshot on a follower.booleancaptureWithForcedTrim(ReplicatedLogEntry 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)CaptureSnapshotgetCaptureSnapshot()longgetLastSequenceNumber()booleanisApplying()booleanisCapturing()Returns whether or not a capture is in progress.CaptureSnapshotnewCaptureSnapshot(ReplicatedLogEntry 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 Detail
-
SnapshotManager
public SnapshotManager(RaftActorContext context, Logger logger)
Constructs an instance.- Parameters:
context- the RaftActorContextlogger- the Logger
-
-
Method Detail
-
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(ReplicatedLogEntry 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
public boolean capture(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex)
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
public boolean captureWithForcedTrim(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex)
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
public void apply(ApplySnapshot snapshot)
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
public @NonNull Snapshot.State convertSnapshot(ByteSource snapshotBytes) throws IOException
- Throws:
IOException
-
getLastSequenceNumber
public long getLastSequenceNumber()
-
getCaptureSnapshot
public CaptureSnapshot getCaptureSnapshot()
-
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.
-
-