View Source Electric.StackSupervisor (electric v0.9.5)

Root supervisor that starts a stack of processes to serve shapes.

Full supervision tree looks roughly like this:

First, we start 2 registries, Electric.ProcessRegistry, and a registry for shape subscriptions. Both are named using the provided stack_id variable.

  1. Electric.Postgres.Inspector.EtsInspector is started with a pool name as a config option, module that is passed from the base config is ignored

  2. Electric.Connection.Supervisor takes a LOT of options to configure replication and start the rest of the tree. It starts (3) and then (4) in rest-for-one mode

  3. Electric.Connection.Manager takes all the connection/replication options and starts the db pool. It goes through the following steps:

    • start_lock_connection
    • exclusive_connection_lock_acquired (as a callback from the lock connection)
    • start_replication_client This starts a replication client (3.1) with no auto-reconnection, because manager is expected to restart this client in case something goes wrong. The streaming of WAL does not start automatically and has to be started explicitly by the manager
    • start_connection_pool (only if it's not started already, otherwise start streaming) This starts a Postgrex connection pool (3.2) to the DB we're going to use. If it's ok, we then do a bunch of checks, then ask (3) to finally start (4), and start streaming
    1. Electric.Postgres.ReplicationClient - connects to PG in replication mod, sets up slots, does not start streaming until requested
    2. Postgrex connection pool is started for querying initial snapshots & info about the DB
  4. Electric.Replication.Supervisor is a supervisor responsible for taking the replication log from the replication client and shoving it into storage appropriately. It starts 3 things in one-for-all mode:

    1. Electric.Shapes.DynamicConsumerSupervisor is DynamicSupervisor. It oversees a per-shape storage & replication log consumer
      1. Electric.Shapes.ConsumerSupervisor supervises the "consumer" part of the replication process, starting 3 children. These are started for each shape.
        1. Electric.ShapeCache.Storage is a process that knows how to write to disk. Takes configuration options for the underlying storage, is an end point
        2. Electric.Shapes.Consumer is GenStage consumer, subscribing to LogCollector, which acts a shared producer for all shapes. It passes any incoming operation along to the storage.
        3. Electric.Shapes.Consumer.Snapshotter is a temporary GenServer that executes initial snapshot query and writes that to storage
    2. Electric.Replication.ShapeLogCollector collects transactions from the replication connection, fanning them out to Electric.Shapes.Consumer (4.1.1.2)
    3. Electric.ShapeCache coordinates shape creation and handle allocation, shape metadata

Summary

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

dispatch_stack_event(registry, stack_id, event)

View Source
Link to this function

subscribe_to_stack_events(registry, stack_id, value)

View Source