Memo for logical replication code reading
Replication side
As of 12.5
- Boot flow
- logical replication launcher assign a subscription to a slot (set slot as main arg)
- bgworker launch logical replication apply worker
Logical replication launcher
- list subscriptions
- launch logical replication worker
Wait if replication slot is not available.
Logical replication apply worker
Entry point Note : this entry point is used for both replication apply worker and table synchronization worker.
Bootstrap
- Launch replication apply worker
- Get replication origin (RepOriginId)
- Connect to publisher
- Start streaming
- Enter main loop
Main loop
Receive WAL and process based on (Replication Protocol)
- Process messages until the buffer will be empty (inner loop)
- “XLogData (B)”
- “Primary keepalive message (B)”
- send feedback Send “Standby status update (F)”
- send_feedback
- reread subscription and process syncing tables if not in remote transaction
- Process all tables that are being synchronized