reckon_db_emitter_pool (reckon_db v5.11.14)

View Source

Emitter pool supervisor for reckon-db

Supervises a pool of emitter workers for a single subscription. Each subscription can have multiple emitter workers for load distribution.

Summary

Functions

Generate the name for an emitter pool

Run Fun in the section a subscription's pool is stopped or re-pointed in, on this node. The pools stopped here are this node's, and a subscriber that re-subscribes does so on its own node.

Start an emitter pool for a subscription

Start the emitter pool supervisor

Stop an emitter pool by key (deprecated, use stop_emitter/2)

Stop an emitter pool for a subscription

Stop the pool of a subscription whose subscriber Dead died, unless the subscription names another subscriber by now.

Update an emitter pool configuration

Types

subscription/0

-type subscription() ::
          #subscription{id :: binary(),
                        type :: subscription_type(),
                        selector :: binary() | map(),
                        subscription_name :: binary(),
                        subscriber_pid :: pid() | undefined,
                        created_at :: integer(),
                        pool_size :: pos_integer(),
                        checkpoint :: non_neg_integer() | undefined,
                        options :: map()}.

subscription_type/0

-type subscription_type() ::
          stream | event_type | event_pattern | event_payload | by_stream | by_event_type |
          by_event_pattern | by_event_payload | by_tags.

Functions

init(_)

name(StoreId, SubscriptionKey)

-spec name(atom(), binary()) -> atom().

Generate the name for an emitter pool

serialized(StoreId, SubscriptionKey, Fun)

-spec serialized(atom(), binary(), fun(() -> Result)) -> Result.

Run Fun in the section a subscription's pool is stopped or re-pointed in, on this node. The pools stopped here are this node's, and a subscriber that re-subscribes does so on its own node.

start_emitter(StoreId, Subscription)

-spec start_emitter(atom(), subscription()) -> {ok, pid()} | {error, term()}.

Start an emitter pool for a subscription

start_link(StoreId, Subscription)

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

Start the emitter pool supervisor

stop(StoreId, SubscriptionKey)

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

Stop an emitter pool by key (deprecated, use stop_emitter/2)

stop_emitter(StoreId, Subscription)

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

Stop an emitter pool for a subscription

stop_for_dead(StoreId, SubscriptionKey, Dead)

-spec stop_for_dead(atom(), binary(), pid()) -> ok | {error, term()}.

Stop the pool of a subscription whose subscriber Dead died, unless the subscription names another subscriber by now.

The emitter that found Dead asks for this asynchronously, so a re-subscribe by the restarted subscriber can come first. It wrote the new pid and saw this pool running, so it started none: stopping the pool then left the new subscriber with no emitters (reckon-db#24). The check and the stop run under serialized/3, the same section as the re-subscribe's write and its pool check, so one of the two always sees what the other did.

update_emitter(StoreId, Subscription)

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

Update an emitter pool configuration