← All compilation units

Flyology.Postgres.Replication.Logical.Producer

Description

Stateful server-side pgoutput encoder. It validates transaction ordering before delegating wire encoding to Logical.Encode and restores its prior state if validation or encoding fails.

Configure

procedure Configure
  (Item      : out Encoder;
   Version   : Protocol_Version;
   Streaming : Streaming_Mode := Disabled)

Initialize an idle producer for a negotiated pgoutput configuration.

Parameters
Item

Producer to initialize.

Version

Negotiated pgoutput protocol version.

Streaming

Negotiated streaming mode.

Raised exceptions
Protocol_Error

Version and Streaming are incompatible.

Emit

function Emit
  (Item      : in out Encoder;
   Message   : Logical.Message;
   WAL_Start : LSN;
   WAL_End   : LSN) return Byte_Array

Validate and encode one message without partially advancing Item on failure. WAL_Start and WAL_End describe its XLogData envelope and may not move backwards relative to earlier successful calls.

Parameters
Item

Configured producer to advance.

Message

Typed pgoutput message to encode.

WAL_Start

Envelope start LSN.

WAL_End

Envelope end LSN and new monotonic producer position.

Return value

Encoded pgoutput bytes.

Raised exceptions
Protocol_Error

The transaction sequence, envelope, or negotiated protocol configuration is invalid.

Encoder

type Encoder is private;

Configured pgoutput producer state for one replication stream.

Last_WAL_End

function Last_WAL_End (Item : Encoder) return LSN

Inspect the last successfully encoded WAL envelope end.

Parameters
Item

Producer to inspect.

Return value

Monotonic end LSN, or zero after configuration or Reset.

Reset

procedure Reset (Item : in out Encoder)

Forget transaction and WAL progress while retaining configuration.

Parameters
Item

Configured producer to return to Idle at LSN zero.

State

function State (Item : Encoder) return Transaction_State

Inspect the current transaction state.

Parameters
Item

Producer to inspect.

Return value

Current transaction state.

Transaction

function Transaction (Item : Encoder) return Transaction_Id

Inspect the active transaction identifier, or the most recently paused streamed transaction when no transaction is currently emitting.

Parameters
Item

Producer to inspect.

Return value

Current XID, or zero while Idle.

Transaction_State

type Transaction_State is
  (Idle, Regular_Transaction, Stream_Segment, Stream_Paused,
   Preparing_Transaction);

Current pgoutput transaction context.

Enumeration literals
Idle

No transaction is open.

Regular_Transaction

Begin was emitted without streaming.

Stream_Segment

A streamed transaction segment is open.

Stream_Paused

One or more streamed transactions are between segments, with no transaction currently emitting.

Preparing_Transaction

BeginPrepare was emitted.