Packages
reckon_db
1.3.1
5.11.0
5.10.4
5.10.3
5.10.1
5.10.0
5.9.1
5.9.0
5.8.3
5.8.2
5.8.1
5.8.0
5.7.0
5.6.1
5.6.0
5.5.5
5.5.4
5.5.3
5.5.2
5.5.1
5.5.0
5.4.0
5.2.2
5.2.1
5.2.0
5.1.0
5.0.0
4.0.0
3.1.2
3.1.1
3.0.0
2.3.7
2.3.6
2.3.5
2.3.4
2.3.3
2.3.2
2.3.1
2.3.0
2.2.2
2.2.0
2.1.4
2.1.3
2.1.2
2.1.1
2.1.0
2.0.0
1.7.7
1.7.6
1.7.5
1.7.4
1.7.3
1.7.2
1.7.1
1.7.0
1.6.3
1.6.2
1.6.1
1.6.0
1.5.1
1.5.0
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.3
1.3.2
1.3.1
1.3.0
1.2.7
1.2.6
1.2.5
1.2.4
1.2.3
1.2.2
1.2.1
1.2.0
1.1.1
1.1.0
1.0.3
1.0.2
1.0.1
1.0.0
BEAM-native Event Store built on Khepri/Ra with Raft consensus. Event sourcing, persistent subscriptions, snapshots, and automatic cluster formation via UDP multicast discovery. Ships embedded Rust NIFs for 3-15x acceleration of crypto, hashing, compression, aggregation, filter matching, and grap...
Current section
Files
Jump to
Current section
Files
src/reckon_db_emitter_sup.erl
%% @doc Emitter supervisor for reckon-db
%%
%% Manages emitter pools for subscriptions. Emitter pools are created
%% dynamically when subscriptions are registered.
%%
%% @author rgfaber
-module(reckon_db_emitter_sup).
-behaviour(supervisor).
-include("reckon_db.hrl").
%% API
-export([start_link/1]).
-export([start_emitter_pool/2, stop_emitter_pool/2]).
%% Supervisor callbacks
-export([init/1]).
%%====================================================================
%% API
%%====================================================================
%% @doc Start the emitter supervisor
-spec start_link(store_config()) -> {ok, pid()} | {error, term()}.
start_link(#store_config{store_id = StoreId} = Config) ->
Name = reckon_db_naming:emitter_sup_name(StoreId),
supervisor:start_link({local, Name}, ?MODULE, Config).
%% @doc Start an emitter pool for a subscription
-spec start_emitter_pool(atom(), subscription()) -> {ok, pid()} | {error, term()}.
start_emitter_pool(StoreId, Subscription) ->
SupName = reckon_db_naming:emitter_sup_name(StoreId),
ChildSpec = emitter_pool_spec(StoreId, Subscription),
supervisor:start_child(SupName, ChildSpec).
%% @doc Stop an emitter pool
-spec stop_emitter_pool(atom(), binary()) -> ok | {error, term()}.
stop_emitter_pool(StoreId, SubscriptionId) ->
SupName = reckon_db_naming:emitter_sup_name(StoreId),
ChildId = reckon_db_naming:emitter_pool_name(StoreId, SubscriptionId),
case supervisor:terminate_child(SupName, ChildId) of
ok ->
supervisor:delete_child(SupName, ChildId);
Error ->
Error
end.
%%====================================================================
%% Supervisor callbacks
%%====================================================================
%% @private
-spec init(store_config()) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
init(#store_config{store_id = StoreId} = _Config) ->
SupFlags = #{
strategy => one_for_one,
intensity => 10,
period => 60
},
%% Emitter pools are started dynamically
Children = [],
logger:debug("Starting emitter supervisor for store ~p", [StoreId]),
{ok, {SupFlags, Children}}.
%%====================================================================
%% Internal functions
%%====================================================================
%% @private
-spec emitter_pool_spec(atom(), subscription()) -> supervisor:child_spec().
emitter_pool_spec(StoreId, #subscription{id = SubId} = Subscription) ->
#{
id => reckon_db_naming:emitter_pool_name(StoreId, SubId),
start => {reckon_db_emitter_pool, start_link, [StoreId, Subscription]},
restart => permanent,
shutdown => infinity,
type => supervisor,
modules => [reckon_db_emitter_pool]
}.