← All compilation units

Flyology.Postgres.Replication.Prepared_Consumer

Description

Recovery coordinator for pgoutput two-phase transactions. Durable prepared state survives consumer replacement, while an applied marker prevents replay after target application has been recorded.

Apply_Target must be idempotent for (Slot_Name, GID, XID), because a process can fail after target commit but before Mark_Target_Applied. An application can eliminate that interval by committing the target change and marker in one transaction.

Acknowledge_Commit

procedure Acknowledge_Commit
  (Item      : in out Consumer;
   Slot_Name : String;
   GID       : String)

Remove Target_Applied state after the source commit LSN has itself been durably acknowledged. Retaining the marker until then bounds replay.

Parameters
Item

Consumer coordinator.

Slot_Name

Logical slot name.

GID

PostgreSQL prepared-transaction identifier.

Raised exceptions
Protocol_Error

Target application is not durably marked.

Store_Error

Durable state disappears before removal.

Apply_Target

procedure Apply_Target
(Context     : in out Target_Context;
Slot_Name  : String;
GID         : String;
XID         : Transaction_Id;
Payload     : Persistence.Byte_Array)
Parameters
Context
Slot_Name
GID
XID
Payload

Commit

procedure Commit
  (Item        : in out Consumer;
   Slot_Name   : String;
   GID         : String;
   Applied_Now : out Boolean)

Apply a prepared transaction once per durable recovery state, then mark Target_Applied. A replacement Consumer sharing Store observes the marker and does not invoke Apply_Target again.

Parameters
Item

Consumer coordinator.

Slot_Name

Logical slot name.

GID

PostgreSQL prepared-transaction identifier.

Applied_Now

True when this call invoked Apply_Target.

Raised exceptions
Protocol_Error

No durable prepared state exists.

Store_Error

The applied marker cannot be persisted.

Consumer

type Consumer
  (Store  : not null access Stores.Prepared_Store'Class;
   Target : not null access Target_Context) is limited private;

Consumer bound to shared prepared state and an application target.

Record fields
Store

Durable prepared-transaction store.

Target

Application context passed to Apply_Target.

Prepare

procedure Prepare
  (Item        : in out Consumer;
   Slot_Name   : String;
   GID         : String;
   XID         : Transaction_Id;
   Prepare_LSN : LSN;
   Payload     : Stores.Byte_Array)

Persist a prepared payload before acknowledging Prepare or StreamPrepare to the source. A replay with the same XID after Target_Applied preserves the durable marker; a different XID using that slot/GID before acknowledgement is rejected.

Parameters
Item

Consumer coordinator.

Slot_Name

Logical slot name.

GID

PostgreSQL prepared-transaction identifier.

XID

Nonzero source transaction identifier.

Prepare_LSN

Nonzero source prepare position.

Payload

Deterministic data required by Apply_Target.

Raised exceptions
Constraint_Error

XID or Prepare_LSN is zero.

Protocol_Error

A different XID reuses a slot/GID whose prior target application remains marked.

Store_Error

The backend cannot durably store the transaction.

Rollback

procedure Rollback
  (Item      : in out Consumer;
   Slot_Name : String;
   GID       : String)

Remove a prepared transaction that has not been applied to the target.

Parameters
Item

Consumer coordinator.

Slot_Name

Logical slot name.

GID

PostgreSQL prepared-transaction identifier.

Raised exceptions
Protocol_Error

State is missing or already applied.

Store_Error

Durable state disappears before removal.

Target_Context

type Target_Context (<>) is limited private;