postgres

package
v0.0.0-...-2ce9d76 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package postgres provides native durable fenced leases for PostgreSQL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoMigration

func GoMigration() (migrations.Migration, error)

GoMigration returns the schema in migrations' immutable format.

Types

type Migration

type Migration struct {
	Version uint
	Name    string
	Up      string
	Down    string
}

Migration describes the reversible PostgreSQL schema contract.

func SchemaMigration

func SchemaMigration() Migration

SchemaMigration returns the durable lease and persistent-fence schema.

type Store

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

Store persists leases and fencing counters in PostgreSQL server time.

func New

func New(pool *pgxpool.Pool) (*Store, error)

New constructs a PostgreSQL backend from a caller-owned pgx pool.

func (*Store) Cleanup

func (store *Store) Cleanup(ctx context.Context, batch uint32) (uint32, error)

Cleanup removes a bounded batch of old inactive lease rows. Fence rows are deliberately retained so cleanup cannot reset monotonic continuity.

func (*Store) Release

func (store *Store) Release(ctx context.Context, owned lease.Record) error

Release atomically deactivates only a matching owner and token.

func (*Store) Renew

func (store *Store) Renew(
	ctx context.Context,
	owned lease.Record,
	ttl time.Duration,
) (lease.Record, error)

Renew atomically compares owner and token before extending backend expiry.

func (*Store) TryAcquire

func (store *Store) TryAcquire(
	ctx context.Context,
	key lease.Key,
	owner string,
	ttl time.Duration,
) (lease.Record, error)

TryAcquire atomically advances the durable fence and installs an owner.

func (*Store) Validate

func (store *Store) Validate(ctx context.Context, owned lease.Record) (lease.Record, error)

Validate checks current owner, token, active state, and backend deadline.

Jump to

Keyboard shortcuts

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