Module nats_buffered

Module nats_buffered 

Source
Expand description

NATS JetStream-buffered storage decorator.

Wraps an inner ThreadWriter (typically PostgreSQL) and routes delta writes through NATS JetStream instead of hitting the database per-delta.

§Run-end flush strategy

During a run the [AgentOs::run_stream] checkpoint background task calls append() for each delta. This storage publishes those deltas to a JetStream subject thread.{thread_id}.deltas so they are durably buffered in NATS. No database writes happen during the run.

When the run emits CheckpointReason::RunFinished, append() triggers a flush for that thread: buffered deltas are materialized and persisted to the inner storage via a single save(). The buffered NATS messages are then acknowledged.

save() remains available for explicit run-end flush when callers already have a final materialized state.

§Crash recovery

On startup, call NatsBufferedThreadWriter::recover to replay any unacked deltas left over from interrupted runs.

Structs§

NatsBufferedThreadWriter
A ThreadWriter decorator that buffers deltas in NATS JetStream and flushes the final thread to the inner storage at run end.

Enums§

NatsBufferedThreadWriterError