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.
Electric.Postgres.Inspector.EtsInspector
is started with a pool name as a config option, module that is passed from the base config is ignoredElectric.Connection.Supervisor
takes a LOT of options to configure replication and start the rest of the tree. It starts (3) and then (4) inrest-for-one
modeElectric.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
Electric.Postgres.ReplicationClient
- connects to PG in replication mod, sets up slots, does not start streaming until requestedPostgrex
connection pool is started for querying initial snapshots & info about the DB
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:Electric.Shapes.DynamicConsumerSupervisor
is DynamicSupervisor. It oversees a per-shape storage & replication log consumerElectric.Shapes.ConsumerSupervisor
supervises the "consumer" part of the replication process, starting 3 children. These are started for each shape.Electric.ShapeCache.Storage
is a process that knows how to write to disk. Takes configuration options for the underlying storage, is an end pointElectric.Shapes.Consumer
is GenStage consumer, subscribing toLogCollector
, which acts a shared producer for all shapes. It passes any incoming operation along to the storage.Electric.Shapes.Consumer.Snapshotter
is a temporary GenServer that executes initial snapshot query and writes that to storage
Electric.Replication.ShapeLogCollector
collects transactions from the replication connection, fanning them out toElectric.Shapes.Consumer
(4.1.1.2)Electric.ShapeCache
coordinates shape creation and handle allocation, shape metadata
Summary
Functions
Returns a specification to start this module under a supervisor.