Class InMemoryCheckpointStore

java.lang.Object
com.tnsai.reliability.InMemoryCheckpointStore
All Implemented Interfaces:
CheckpointStore

public final class InMemoryCheckpointStore extends Object implements 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-run TreeMap 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 Details

    • InMemoryCheckpointStore

      public InMemoryCheckpointStore()
  • Method Details

    • save

      public void save(Checkpoint cp)
      Description copied from interface: CheckpointStore
      Persist 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:
      save in interface CheckpointStore
    • latest

      public Optional<Checkpoint> latest(String runId)
      Specified by:
      latest in interface CheckpointStore
      Returns:
      the highest-stepIndex checkpoint known for runId, or empty when the store has none.
    • history

      public List<Checkpoint> history(String runId)
      Specified by:
      history in interface CheckpointStore
      Returns:
      all checkpoints for runId, ordered by ascending stepIndex. 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

      public void truncate(String runId, Instant before)
      Description copied from interface: CheckpointStore
      Drop every checkpoint for runId captured strictly before before. 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:
      truncate in interface CheckpointStore
    • size

      public int size()
      Test helper: total checkpoint count across all runs.
    • clear

      public void clear()
      Test helper: drop every entry.