Documentation
¶
Overview ¶
Package replication manages what logical replication needs on the server before the stream starts: the slot, the publication and each table's replica identity. It also reads and advances the slot's confirmed LSN.
Index ¶
- func AdvanceSlot(ctx context.Context, db *sql.DB, slotName string, target position.LSN) error
- func ConfirmedLSN(ctx context.Context, db *sql.DB, slotName string) (*position.LSN, error)
- func EnsureSetup(ctx context.Context, db *sql.DB, slotName string, tables []source.TableRef, ...) error
- func PublicationFor(slotName string) string
- func ValidateSlotState(ctx context.Context, db *sql.DB, slotName string, resume *position.LSN, ...) (*position.LSN, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AdvanceSlot ¶
AdvanceSlot advances the logical slot's confirmed_flush_lsn to target, letting the server recycle WAL the sink has already committed (#156). It is idempotent and must run while the slot is inactive — before START_REPLICATION attaches the walsender.
func ConfirmedLSN ¶
ConfirmedLSN reads the slot's confirmed_flush_lsn: the stream start for a first boot (no committed resume position).
func EnsureSetup ¶
func EnsureSetup(ctx context.Context, db *sql.DB, slotName string, tables []source.TableRef, plugin, replicaIdentity string) error
EnsureSetup makes the server side ready, idempotently:
- REPLICA IDENTITY FULL on every replicated table, so updates and deletes carry the full old row (parity with MySQL's row_image=FULL);
- for pgoutput, the logical publication listing exactly the pipeline's tables;
- the logical decoding slot with the selected plugin.
The slot is the consistency anchor: created before the snapshot starts, it guarantees no transaction between slot creation and the stream start is ever lost.
func PublicationFor ¶
PublicationFor derives the publication name from the slot name: one publication per pipeline slot.
func ValidateSlotState ¶
func ValidateSlotState(ctx context.Context, db *sql.DB, slotName string, resume *position.LSN, logger *slog.Logger) (*position.LSN, error)
ValidateSlotState reconciles a stored resume LSN with the slot's confirmed_flush_lsn and returns the LSN the stream should start from (#156):
- resume == nil (first boot): start from the slot's confirmed point.
- resume == confirmed: no drift.
- resume < confirmed: the slot is ahead of the sink. The sink's stored point is behind what the server already confirmed (and may have recycled), so the slot's point is authoritative — warn and use it.
- resume > confirmed: the sink durably committed past the slot's last confirmed_flush_lsn (the server learns the applied position from a later standby-status update, so a crash can leave the slot behind). This is recoverable: the WAL from resume onward is still retained because the slot never confirmed past it, so advance the slot to the sink's point rather than forcing a re-snapshot.
Types ¶
This section is empty.