Class SnapshotScheduler
java.lang.Object
com.loomcache.server.persistence.SnapshotScheduler
Schedules and manages state machine snapshots for Raft log compaction.
Automatically triggers snapshots after a configured number of committed entries, using virtual threads to avoid blocking the Raft processing thread.
Maintains bounded storage by retaining only the latest N snapshots.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordStatistics about snapshot scheduler activity. -
Constructor Summary
ConstructorsConstructorDescriptionSnapshotScheduler(StateMachineSnapshotManager snapshotManager) Create a snapshot scheduler with default configuration.SnapshotScheduler(StateMachineSnapshotManager snapshotManager, long snapshotIntervalEntries, int maxSnapshotsToRetain) Create a snapshot scheduler with custom configuration and default delta count (3).SnapshotScheduler(StateMachineSnapshotManager snapshotManager, long snapshotIntervalEntries, int maxSnapshotsToRetain, int maxDeltasBetweenFullSnapshots) Create a snapshot scheduler with custom configuration. -
Method Summary
Modifier and TypeMethodDescriptionlongGet the index of the last snapshot taken.getStats()Get current scheduler statistics.voidmaybeSnapshot(long currentCommittedIndex, long currentTerm, Map<String, ? extends Snapshotable> dataStructures) Check if a snapshot should be triggered based on the committed index.voidsetLastSnapshotIndex(long index) Set the last snapshot index (useful for recovery).
-
Constructor Details
-
SnapshotScheduler
public SnapshotScheduler(StateMachineSnapshotManager snapshotManager, long snapshotIntervalEntries, int maxSnapshotsToRetain, int maxDeltasBetweenFullSnapshots) Create a snapshot scheduler with custom configuration.- Parameters:
snapshotManager- the underlying snapshot managersnapshotIntervalEntries- trigger snapshot after this many committed entries (default: 10000)maxSnapshotsToRetain- keep at most this many snapshots (default: 3)maxDeltasBetweenFullSnapshots- max delta snapshots before forcing a full snapshot (default: 3)
-
SnapshotScheduler
public SnapshotScheduler(StateMachineSnapshotManager snapshotManager, long snapshotIntervalEntries, int maxSnapshotsToRetain) Create a snapshot scheduler with custom configuration and default delta count (3).- Parameters:
snapshotManager- the underlying snapshot managersnapshotIntervalEntries- trigger snapshot after this many committed entriesmaxSnapshotsToRetain- keep at most this many snapshots
-
SnapshotScheduler
Create a snapshot scheduler with default configuration. Default: snapshot every 10,000 committed entries, retain 3 snapshots, max 3 deltas.- Parameters:
snapshotManager- the underlying snapshot manager
-
-
Method Details
-
maybeSnapshot
public void maybeSnapshot(long currentCommittedIndex, long currentTerm, Map<String, ? extends Snapshotable> dataStructures) Check if a snapshot should be triggered based on the committed index. If needed, trigger snapshot asynchronously using a virtual thread.- Parameters:
currentCommittedIndex- the current Raft committed log indexcurrentTerm- the current Raft termdataStructures- the data structures to snapshot
-
getStats
Get current scheduler statistics.- Returns:
- SnapshotSchedulerStats with current metrics
-
getLastSnapshotIndex
public long getLastSnapshotIndex()Get the index of the last snapshot taken.- Returns:
- the last snapshot index, or -1 if no snapshots taken yet
-
setLastSnapshotIndex
public void setLastSnapshotIndex(long index) Set the last snapshot index (useful for recovery).- Parameters:
index- the index to set
-