postgres

package
v1.0.31-beta.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package postgres provides a PostgreSQL-backed durable relay operation log. It is intentionally separate from durable so applications opt into the database driver and own pool construction, credentials, TLS, and migrations.

Index

Constants

This section is empty.

Variables

View Source
var ErrSequenceRange = errors.New("crdt postgres provider: sequence exceeds PostgreSQL bigint range")

Functions

This section is empty.

Types

type Config

type Config struct {
	MaxEvents uint64
	MaxBytes  uint64
	Timeout   time.Duration
}

Config bounds one retained operation log per group. Timeout applies to each Append and Replay call because durable.Log intentionally has no context parameter; connection and pool lifetime remain application-owned.

type Pool

type Pool interface {
	BeginTx(context.Context, pgx.TxOptions) (pgx.Tx, error)
	Exec(context.Context, string, ...any) (pgconn.CommandTag, error)
}

Pool is the minimum pgx pool surface used by Store. *pgxpool.Pool satisfies it directly; keeping the port narrow also permits deterministic SQL-path tests without a running database.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store implements durable.Log with one row lock per group. It does not close the supplied pool, which may be shared by multiple relay handlers.

func New

func New(pool Pool, config Config) (*Store, error)

New validates provider limits. Call EnsureSchema with a migration role before accepting traffic; runtime applications should grant only the needed table privileges to the relay role.

func (*Store) Append

func (store *Store) Append(groupID string, change replica.Change) (durable.AppendResult, error)

Append atomically verifies a retry's payload digest, reserves a sequence, persists its envelope, and updates capacity accounting under a group row lock. PostgreSQL BIGINT intentionally limits provider sequences and dots to MaxInt64; applications must rotate/bootstrap long before that boundary.

func (*Store) Close

func (store *Store) Close() error

Close marks this Store unavailable. It deliberately does not close pool.

func (*Store) Closed

func (store *Store) Closed() bool

Closed implements durable.Log.

func (*Store) EnsureSchema

func (store *Store) EnsureSchema(ctx context.Context) error

EnsureSchema creates the fixed provider tables. It is intentionally an explicit migration step rather than hidden startup DDL.

func (*Store) Replay

func (store *Store) Replay(groupID string, after, maxEvents, maxBytes uint64, manifest replica.Manifest, policy crdt.ProtocolPolicy, maxMessageBytes, maxActorBytes int) ([]durable.Event, uint64, error)

Replay reads one repeatable PostgreSQL snapshot and refuses a partial, corrupt, over-budget, or manifest-incompatible suffix.

Jump to

Keyboard shortcuts

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