← All compilation units

Flyology.Postgres.Replication.Persistence.Memory

Description

Bounded volatile reference implementation of every persistence interface. It is deterministic and intended for tests or ephemeral single-owner servers; it is neither concurrent nor crash durable.

Acquire

procedure Acquire
  (Item       : in out Store;
   Name       : String;
   Expected   : Slot_Kind;
   Result     : out Acquire_Result;
   Lease      : out UInt64;
   State      : out Slot_State)

Acquire an exclusive generation lease according to Slot_Store.Acquire.

Parameters
Item

Memory store to mutate.

Name

Slot name.

Expected

Required slot category.

Result

Acquisition outcome.

Lease

New nonzero generation on success, otherwise zero.

State

Snapshot associated with Result.

Advance

procedure Advance
  (Item          : in out Store;
   Name          : String;
   Lease         : UInt64;
   Restart       : LSN;
   Confirmed     : LSN;
   Advanced      : out Boolean)

Conditionally advance monotonic slot positions in memory.

Parameters
Item

Memory store to mutate.

Name

Slot name.

Lease

Active generation.

Restart

New restart position.

Confirmed

New confirmed position; use zero when not applicable.

Advanced

Whether the active lease and monotonicity checks passed.

Append

procedure Append
  (Item  : in out Store;
   Start : LSN;
   Data  : Byte_Array)

Append bytes at the exact current end position.

Parameters
Item

Memory store to mutate.

Start

Current_LSN, or a new base for an empty store.

Data

WAL bytes to append.

Raised exceptions
Store_Error

A nonempty append is not contiguous.

Capacity

Capacity : Positive := 32;

Create

procedure Create
  (Item   : in out Store;
   Name   : String;
   State  : Slot_State;
   Result : out Create_Result)

Create a slot according to Slot_Store.Create.

Parameters
Item

Memory store to mutate.

Name

Nonempty slot name.

State

Initial state created by Make_Slot.

Result

Creation outcome.

Raised exceptions
Store_Error

State is invalid or capacity is exhausted.

Current_LSN

function Current_LSN (Item : Store) return LSN

Read the in-memory WAL end.

Parameters
Item

Memory store to query.

Return value

Exclusive end LSN.

Current_Timeline

function Current_Timeline (Item : Store) return UInt32

Read the current in-memory timeline.

Parameters
Item

Memory store to query.

Return value

Current timeline, initially one.

Drop

procedure Drop
  (Item    : in out Store;
   Name    : String;
   Dropped : out Boolean)

Drop an inactive slot according to Slot_Store.Drop.

Parameters
Item

Memory store to mutate.

Name

Slot name.

Dropped

Whether a stored inactive slot was removed.

First_LSN

function First_LSN (Item : Store) return LSN

Read the in-memory WAL base.

Parameters
Item

Memory store to query.

Return value

Inclusive first retained LSN.

History

function History
  (Item : Store; Timeline : UInt32) return Byte_Array

Copy a stored timeline history file.

Parameters
Item

Memory store to query.

Timeline

Timeline identifier.

Return value

Exact history bytes, or an empty array when absent.

Invalidate

procedure Invalidate
  (Item        : in out Store;
   Name        : String;
   Invalidated : out Boolean)

Invalidate a stored slot.

Parameters
Item

Memory store to mutate.

Name

Slot name.

Invalidated

Whether the named slot existed.

Load

function Load
  (Item : Store; Name : String) return Slot_State

Load a slot snapshot according to Slot_Store.Load.

Parameters
Item

Memory store to query.

Name

Slot name.

Return value

Stored state, or No_Slot.

Load

function Load
  (Item      : Store;
   Slot_Name : String;
   GID       : String) return Prepared_Transaction

Load prepared state by slot and GID.

Parameters
Item

Memory store to query.

Slot_Name

Logical slot name.

GID

Prepared-transaction identifier.

Return value

Stored state, or No_Prepared_Transaction.

Mark_Target_Applied

procedure Mark_Target_Applied
  (Item      : in out Store;
   Slot_Name : String;
   GID       : String;
   Changed   : out Boolean)

Atomically change Prepared state to Target_Applied.

Parameters
Item

Memory store to mutate.

Slot_Name

Logical slot name.

GID

Prepared-transaction identifier.

Changed

Whether this call performed the transition.

Oldest_Restart_LSN

function Oldest_Restart_LSN (Item : Store) return LSN

Compute the non-invalidated slot retention floor.

Parameters
Item

Memory store to query.

Return value

Oldest restart LSN, or zero when no slot retains WAL.

Promote

procedure Promote
  (Item         : in out Store;
   Parent       : UInt32;
   Fork_LSN     : LSN;
   New_Timeline : out UInt32)

Persist a PostgreSQL-format history line and advance the timeline.

Parameters
Item

Memory store to mutate.

Parent

Timeline that must still be current.

Fork_LSN

Nonzero fork position.

New_Timeline

Newly current timeline.

Raised exceptions
Store_Error

Parent, fork, or capacity is invalid.

Put

procedure Put
  (Item        : in out Store;
   Slot_Name   : String;
   GID         : String;
   Transaction : Prepared_Transaction)

Insert or replace prepared state by slot and GID.

Parameters
Item

Memory store to mutate.

Slot_Name

Nonempty logical slot name.

GID

Nonempty prepared-transaction identifier.

Transaction

Complete prepared state.

Raised exceptions
Store_Error

Input is invalid or capacity is exhausted.

Read

function Read
  (Item    : Store;
   Start   : LSN;
   Maximum : Positive) return Byte_Array

Copy a bounded retained WAL range.

Parameters
Item

Memory store to query.

Start

Inclusive retained LSN.

Maximum

Maximum bytes to return.

Return value

Contiguous WAL bytes, possibly empty at Current_LSN.

Raised exceptions
Store_Error

Start is outside the retained range.

Release

procedure Release
  (Item     : in out Store;
   Name     : String;
   Lease    : UInt64;
   Released : out Boolean)

Release a matching active generation lease.

Parameters
Item

Memory store to mutate.

Name

Slot name.

Lease

Active generation.

Released

Whether the matching lease was released.

Remove

procedure Remove
  (Item      : in out Store;
   Slot_Name : String;
   GID       : String;
   Removed   : out Boolean)

Remove prepared state by slot and GID.

Parameters
Item

Memory store to mutate.

Slot_Name

Logical slot name.

GID

Prepared-transaction identifier.

Removed

Whether stored state was removed.

Retain_From

procedure Retain_From
  (Item : in out Store; Oldest : LSN)

Discard the WAL prefix before Oldest.

Parameters
Item

Memory store to mutate.

Oldest

New inclusive first retained LSN.

Raised exceptions
Store_Error

Oldest exceeds Current_LSN.

Store

type Store is limited new Slot_Store and WAL_Store and Timeline_Store
  and Prepared_Store with private;

In-memory implementation sharing one bounded state allocation across slot, WAL, timeline, and prepared-transaction operations.