reckon_db_snapshot_backend behaviour (reckon_db v3.1.1)

View Source

Behaviour for pluggable snapshot backends.

Aggregate snapshots are a COLD PATH — written periodically by evoq's maybe_snapshot/1 trigger, read only during aggregate rehydration. Not the bottleneck that drove the log-backend split, but equally worth isolating so a backend can specialise (e.g., a RocksDB log backend could either reuse its column families for snapshots, or delegate to the Khepri control plane).

The default implementation (reckon_db_khepri_snapshot_backend) stores snapshots in Khepri — completely fine for cold-path use. Alternative implementations exist primarily to avoid the Khepri dependency when a backend wants to be self-contained.

Summary

Types

snapshot_data/0

-type snapshot_data() :: map() | binary().

source_id/0

-type source_id() :: binary().

aggregate id

state/0

-type state() :: term().

stream_id/0

-type stream_id() :: binary().

version/0

-type version() :: non_neg_integer().

Callbacks

close/1

-callback close(state()) -> ok.

delete/3

-callback delete(state(), source_id(), stream_id()) -> ok | {error, term()}.

exists/3

-callback exists(state(), source_id(), stream_id()) -> boolean().

init/1

-callback init(Opts :: map()) -> {ok, state()} | {error, term()}.

list/2

-callback list(state(), stream_id()) ->
                  {ok, [#{version := version(), source_id := source_id()}]} | {error, term()}.

load/3

-callback load(state(), source_id(), stream_id()) ->
                  {ok, #{version := version(), data := snapshot_data()}} |
                  {error, not_found} |
                  {error, term()}.

load_at/4

-callback load_at(state(), source_id(), stream_id(), version()) ->
                     {ok, snapshot_data()} | {error, not_found} | {error, term()}.

save/5

-callback save(state(), source_id(), stream_id(), version(), snapshot_data()) -> ok | {error, term()}.