Class RedisCheckpointStore

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

public final class RedisCheckpointStore extends Object implements CheckpointStore
Distributed CheckpointStore backed by Redis (TNS-312). Use this when the framework runs as more than one process and a run started on box A needs to be resumable on box B.

Key layout

  • <prefix><runId>:<stepIndex> — JSON-encoded checkpoint envelope (string value).
  • <prefix><runId>:idx — sorted set scoring members by stepIndex; lets latest(java.lang.String) return in O(log N) via ZRANGE -1 -1 and history(java.lang.String) via ZRANGE 0 -1.

Concurrency

Commands use the caller-owned, pooled RedisClient. The caller closes the client at application shutdown; store operations never close it. save(com.tnsai.reliability.Checkpoint) writes the blob and updates the sorted set in two commands; the small race window is acceptable for the operator-facing read paths (history may briefly see the new index without the corresponding blob — the reader skips such entries gracefully).

Optional dependency

redis.clients:jedis is declared <optional>true</optional> on tnsai-core; loading this class without Jedis on the classpath is a hard NoClassDefFoundError, by design.

Key prefix

Default "tnsai:cp:". Customise for shared Redis clusters to avoid colliding with other TnsAI deployments — same convention as RedisIdempotencyStore.
Since:
0.10.0 (TNS-312)
  • Field Details

    • DEFAULT_KEY_PREFIX

      public static final String DEFAULT_KEY_PREFIX
      Default key prefix; safe for sole-tenant Redis.
      See Also:
  • Constructor Details

    • RedisCheckpointStore

      public RedisCheckpointStore(redis.clients.jedis.RedisClient client)
      Uses DEFAULT_KEY_PREFIX with a caller-owned client; the store never closes it.
      Since:
      0.17.5
    • RedisCheckpointStore

      public RedisCheckpointStore(redis.clients.jedis.RedisClient client, String keyPrefix)
      Uses a caller-owned client; the store never closes it.
      Since:
      0.17.5
  • 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