← All compilation units

Flyology.Postgres.Replication.Managed_Primary

Description

Replication-command handler composed from application-owned slot, WAL, timeline, and logical-change state. Each START_REPLICATION call streams the currently exposed range, persists acknowledged progress, and closes COPY BOTH in PostgreSQL protocol order.

Next_Logical is called repeatedly with the last emitted position. It returns Available = False only between transactions. When available, WAL_Start must be at or after After_LSN, WAL_End must be greater than WAL_Start, and Message must continue a valid pgoutput sequence.

Handle

procedure Handle
  (Item    : in out Primary;
   Client  : in out Sessions.Session;
   Command : Replication.Command)

Handle one decoded replication command. START_REPLICATION acquires the requested slot, streams application data, waits for sufficient standby feedback or frontend CopyDone, persists non-regressing reported progress, releases the lease, applies WAL retention, and completes COPY BOTH.

Parameters
Item

Initialized managed primary.

Client

Authenticated replication-mode server session.

Command

Decoded IDENTIFY_SYSTEM, SHOW, TIMELINE_HISTORY, slot lifecycle, or START_REPLICATION command. Slot creation supports SNAPSHOT 'use' and 'nothing'; an exported snapshot must be composed with an application SQL snapshot provider. DROP WAIT polls until the slot becomes inactive or the configured operation timeout expires.

Raised exceptions
Protocol_Error

Configuration, source ordering, feedback, slot state, or protocol completion is invalid.

Initialize

procedure Initialize
  (Item      : in out Primary;
   System_Id : UInt64;
   Database  : String := "";
   Timeout   : Duration := 30.0)

Configure the identity and operation deadline used by Handle.

Parameters
Item

Primary to initialize.

System_Id

Stable nonzero PostgreSQL system identifier.

Database

Database reported by IDENTIFY_SYSTEM, or an empty string for a physical-only connection.

Timeout

Positive timeout for each protocol operation.

Raised exceptions
Constraint_Error

System_Id is zero or Timeout is not positive.

Logical_Context

type Logical_Context (<>) is limited private;

Next_Logical

procedure Next_Logical
(Context    : in out Logical_Context;
Slot_Name : String;
After_LSN  : LSN;
Available  : out Boolean;
WAL_Start  : out LSN;
WAL_End    : out LSN;
Message    : out Logical.Message)
Parameters
Context
Slot_Name
After_LSN
Available
WAL_Start
WAL_End
Message

Primary

type Primary
  (Slots          : not null access Stores.Slot_Store'Class;
   WAL            : not null access Stores.WAL_Store'Class;
   Timelines      : not null access Stores.Timeline_Store'Class;
   Logical_Source : not null access Logical_Context) is limited private;

Managed primary bound to application-owned replication state.

Record fields
Slots

Durable physical and logical slot catalog.

WAL

Contiguous retained WAL source.

Timelines

Durable current timeline and history source.

Logical_Source

Application pgoutput change source.