Electric.StackSupervisor (electric v1.2.4)
View SourceRoot 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.EtsInspectoris started with a pool name as a config option, module that is passed from the base config is ignoredElectric.Connection.Supervisortakes a LOT of options to configure replication and start the rest of the tree. It starts (3) and then (4) inrest-for-onemodeElectric.Connection.Managertakes 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
Postgrexconnection 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 requestedPostgrexconnection pool is started for querying initial snapshots & info about the DB
Electric.Shapes.Supervisoris 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.DynamicConsumerSupervisoris DynamicSupervisor. It oversees a per-shape storage & replication log consumerElectric.Shapes.ConsumerSupervisorsupervises the "consumer" part of the replication process, starting 3 children. These are started for each shape.Electric.ShapeCache.Storageis a process that knows how to write to disk. Takes configuration options for the underlying storage, is an end pointElectric.Shapes.Consumeris a consumer subscribing toLogCollector, which acts a shared producer for all shapes. It passes any incoming operation along to the storage.Electric.Shapes.Consumer.Snapshotteris a temporary GenServer that executes initial snapshot query and writes that to storage
Electric.Replication.PublicationManagermanages all filters on the publication for the replicationElectric.Replication.ShapeLogCollectorcollects transactions from the replication connection, fanning them out toElectric.Shapes.Consumer(4.1.1.2)Electric.ShapeCachecoordinates shape creation and handle allocation, shape metadata
Summary
Functions
Returns a specification to start this module under a supervisor.