Package com.tnsai.reliability
Class RedisCheckpointStore
java.lang.Object
com.tnsai.reliability.RedisCheckpointStore
- All Implemented Interfaces:
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 bystepIndex; letslatest(java.lang.String)return in O(log N) viaZRANGE -1 -1andhistory(java.lang.String)viaZRANGE 0 -1.
Concurrency
Commands use the caller-owned, pooledRedisClient. 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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault key prefix; safe for sole-tenant Redis. -
Constructor Summary
ConstructorsConstructorDescriptionRedisCheckpointStore(redis.clients.jedis.RedisClient client) UsesDEFAULT_KEY_PREFIXwith a caller-owned client; the store never closes it.RedisCheckpointStore(redis.clients.jedis.RedisClient client, String keyPrefix) Uses a caller-owned client; the store never closes it. -
Method Summary
Modifier and TypeMethodDescriptionvoidsave(Checkpoint cp) Persist a checkpoint.voidDrop every checkpoint forrunIdcaptured strictly beforebefore.
-
Field Details
-
DEFAULT_KEY_PREFIX
Default key prefix; safe for sole-tenant Redis.- See Also:
-
-
Constructor Details
-
RedisCheckpointStore
public RedisCheckpointStore(redis.clients.jedis.RedisClient client) UsesDEFAULT_KEY_PREFIXwith a caller-owned client; the store never closes it.- Since:
- 0.17.5
-
RedisCheckpointStore
Uses a caller-owned client; the store never closes it.- Since:
- 0.17.5
-
-
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
-