reckon_db_store_registry (reckon_db v2.3.2)
View SourceDistributed store registry for reckon-db
Provides cluster-wide store registration and discovery using Erlang's built-in pg (process groups) module for distributed membership.
Architecture
Each node runs a store registry GenServer that:
- Maintains a local list of known stores (from all nodes)
- Announces local stores to registries on other nodes
- Receives announcements from other nodes
- Uses pg groups for registry discovery
Cluster-Wide Discovery
When a store starts on any node:
1. Local store calls announce_store/2 with its config
2. Registry adds store to local state
3. Registry broadcasts to all other registries via pg
4. Other registries add the store to their state
When a node goes down, pg automatically notifies remaining nodes and registries remove stores from the dead node.
Summary
Functions
Announce a store to the cluster
Get detailed information about a specific store
List all known stores in the cluster
List stores on a specific node
Start the store registry
Subscribe a process to live store-registry events. The subscriber receives messages of the form {store_event, announced | retired, EntryMap} as stores come and go anywhere in the cluster. Used by the gRPC WatchStores RPC and any in-BEAM watcher that needs live cluster topology.
Unannounce a store from the cluster
Types
-type integrity_config() :: disabled | #{enabled := true, key_source := integrity_key_source()}.
-type integrity_key_source() :: {env_var, EnvName :: binary()} | {sealed_file, Path :: file:filename()}.
-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()}.
-type store_entry() :: #store_entry{store_id :: atom(), node :: node(), config :: store_config(), registered_at :: integer()}.
Functions
-spec announce_store(atom(), store_config()) -> ok.
Announce a store to the cluster
Called by reckon_db_store when a store starts. This registers the store locally and broadcasts to all other registries in the cluster.
Get detailed information about a specific store
List all known stores in the cluster
Returns stores from all nodes, including their node and config information.
List stores on a specific node
Start the store registry
-spec subscribe(pid()) -> ok.
Subscribe a process to live store-registry events. The subscriber receives messages of the form {store_event, announced | retired, EntryMap} as stores come and go anywhere in the cluster. Used by the gRPC WatchStores RPC and any in-BEAM watcher that needs live cluster topology.
Subscribers are automatically removed if they crash (we monitor them). Safe to call multiple times — no-op if already subscribed.
-spec unannounce_store(atom()) -> ok.
Unannounce a store from the cluster
Called when a store is stopping. Removes the store from local registry and broadcasts removal to all other registries.
-spec unsubscribe(pid()) -> ok.