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 void
apply(ApplySnapshot snapshot)
Applies a snapshot on a follower that was installed by the leader.boolean
capture(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex)
Initiates a capture snapshot.boolean
captureToInstall(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex, String targetFollower)
Initiates a capture snapshot for the purposing of installing the snapshot on a follower.void
commit(long sequenceNumber, long timeStamp)
Commit the snapshot by trimming the log.@NonNull Snapshot.State
convertSnapshot(ByteSource snapshotBytes)
CaptureSnapshot
getCaptureSnapshot()
long
getLastSequenceNumber()
boolean
isApplying()
boolean
isCapturing()
Returns whether or not a capture is in progress.CaptureSnapshot
newCaptureSnapshot(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex)
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 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: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(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 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: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
-
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 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
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)
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.
-
-