replication

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdvanceSlot

func AdvanceSlot(ctx context.Context, db *sql.DB, slotName string, target position.LSN) error

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

func ConfirmedLSN(ctx context.Context, db *sql.DB, slotName string) (*position.LSN, error)

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

func PublicationFor(slotName string) string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL