Package com.tnsai.reliability
Class InMemoryCheckpointStore
java.lang.Object
com.tnsai.reliability.InMemoryCheckpointStore
- All Implemented Interfaces:
CheckpointStore
Process-local
CheckpointStore (TNS-299). Stores checkpoints
in a ConcurrentHashMap keyed by run id, with a
TreeMap per run to keep step-indexed entries ordered.
Useful for tests, single-process workloads, and as the
"checkpointing is on" baseline before swapping in a durable store.
Does NOT survive process restarts — FilesystemCheckpointStore
or SqliteCheckpointStore for that.
Concurrency
Each per-runTreeMap is guarded by synchronizing on itself
during writes. Reads acquire the same lock briefly to take a defensive
snapshot — keeps history(java.lang.String) consistent under concurrent
save(com.tnsai.reliability.Checkpoint) calls.- Since:
- 0.10.0 (TNS-299)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Test helper: drop every entry.voidsave(Checkpoint cp) Persist a checkpoint.intsize()Test helper: total checkpoint count across all runs.voidDrop every checkpoint forrunIdcaptured strictly beforebefore.
-
Constructor Details
-
InMemoryCheckpointStore
public InMemoryCheckpointStore()
-
-
Method Details
-
save
Description copied from interface:CheckpointStorePersist a checkpoint. Returns when the entry is durable — see "Durability" in the type-level javadoc. Overwrites any prior checkpoint with the same(runId, stepIndex)pair so a step that retries can replace its earlier snapshot.- Specified by:
savein interfaceCheckpointStore
-
latest
- Specified by:
latestin interfaceCheckpointStore- Returns:
- the highest-
stepIndexcheckpoint known forrunId, or empty when the store has none.
-
history
- Specified by:
historyin interfaceCheckpointStore- Returns:
- all checkpoints for
runId, ordered by ascendingstepIndex. Empty list when no checkpoints exist. Implementations may impose a soft cap when histories grow unbounded; document the cap in their javadoc when they do.
-
truncate
Description copied from interface:CheckpointStoreDrop every checkpoint forrunIdcaptured strictly beforebefore. Leaves the latest entry if it falls on or after the cutoff so resume continues to work. Used by retention jobs; not on the run's hot path.- Specified by:
truncatein interfaceCheckpointStore
-
size
public int size()Test helper: total checkpoint count across all runs. -
clear
public void clear()Test helper: drop every entry.
-