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.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 pools. It goes through the following steps:- start_admin_pool Starts an admin connection pool (3.1) using replication credentials before the lock is acquired. This pool is available for operations like lock breaking, shutdown cleanup, and ETS inspector cache population.
- start_replication_client This starts a replication client (3.2) 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. The replication client acquires the advisory lock, creates/verifies the publication and slot.
- start_snapshot_pool Starts a snapshot connection pool (3.3) using pooled credentials after the replication client is configured. If it's ok, we then do a bunch of checks, then ask (3) to finally start (4), and start streaming.
Postgrexadmin pool - small pool (1-4 connections) for metadata/admin operationsElectric.Postgres.ReplicationClient- connects to PG in replication mode, sets up slots, does not start streaming until requestedPostgrexsnapshot pool - larger pool 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 various per-shape processesElectric.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 storageElectric.Shapes.Consumer.Materializermonitors a sub-shape in order to invalidate dependent shapes
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.