reckon_db_store (reckon_db v5.8.1)

View Source

Khepri store lifecycle management for reckon-db

Manages the Khepri store instance, including: - Starting and stopping the store - Cluster formation (in cluster mode) - Health checks

Summary

Functions

Idempotently (re)start this store's local Khepri/Ra server.

Get the current leader node for the store

Get the store name (for use with khepri operations)

Check if the store is ready

Start the store worker IMPORTANT: We use store_worker_name/1 for gen_server registration to avoid conflicting with Khepri's internal naming. Khepri uses the StoreId for its Ra cluster and process registration.

Types

index_decl/0

-type index_decl() ::
          tags | event_type |
          {meta, Key :: binary()} |
          {payload, Key :: binary()} |
          {payload_hash, Keys :: [binary()]}.

integrity_config/0

-type integrity_config() :: disabled | #{enabled := true, key_source := integrity_key_source()}.

integrity_key_source/0

-type integrity_key_source() :: {env_var, EnvName :: binary()} | {sealed_file, Path :: file:filename()}.

store_config/0

-type store_config() ::
          #store_config{store_id :: atom(),
                        data_dir :: string(),
                        mode :: single | cluster,
                        timeout :: pos_integer(),
                        writer_pool_size :: pos_integer(),
                        reader_pool_size :: pos_integer(),
                        gateway_pool_size :: pos_integer(),
                        options :: map(),
                        integrity :: integrity_config(),
                        indexes :: [index_decl()]}.

Functions

ensure_khepri_started(StoreId)

-spec ensure_khepri_started(atom()) -> ok | {error, term()}.

Idempotently (re)start this store's local Khepri/Ra server.

The cluster coordinator calls this to self-heal a local store that was torn down by a reset-during-join: khepri_cluster:join resets the local store as part of joining, so a join interrupted mid-reset (e.g. the coordinator's timeout guard killed it) can leave the local Ra server gone — with the coordinator then looping forever on "not registered". A no-op when the server is already registered.

get_leader(StoreId)

-spec get_leader(atom()) -> {ok, node()} | {error, term()}.

Get the current leader node for the store

get_store(StoreId)

-spec get_store(atom()) -> atom().

Get the store name (for use with khepri operations)

is_ready(StoreId)

-spec is_ready(atom()) -> boolean().

Check if the store is ready

start_link(Store_config)

-spec start_link(store_config()) -> {ok, pid()} | {error, term()}.

Start the store worker IMPORTANT: We use store_worker_name/1 for gen_server registration to avoid conflicting with Khepri's internal naming. Khepri uses the StoreId for its Ra cluster and process registration.