postgres

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Overview

Package postgres provides persistent server-time fenced leases.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Migration

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

Migration contains the versioned lease-table schema transition.

func SchemaMigration

func SchemaMigration() Migration

SchemaMigration returns the PostgreSQL lease-table migration.

func SchemaMigrationFor

func SchemaMigrationFor(schema string) (Migration, error)

SchemaMigrationFor returns the lease-table migration for a caller-owned schema. The schema itself must already exist.

type Store

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

Store persists fenced leases in PostgreSQL server time.

func New

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

New constructs a PostgreSQL lease store from a connection pool.

func NewWithSchema

func NewWithSchema(
	pool *pgxpool.Pool,
	schema string,
) (*Store, error)

NewWithSchema constructs a PostgreSQL lease store in a caller-owned schema. Schema must be a lower-case PostgreSQL identifier no longer than 63 bytes.

func (*Store) Acquire

func (store *Store) Acquire(
	ctx context.Context,
	key string,
	owner string,
	ttl time.Duration,
	_ time.Time,
) (lease.Lease, error)

Acquire creates or takes over an inactive or expired lease.

func (*Store) Capabilities

func (*Store) Capabilities() lease.Capabilities

Capabilities reports the PostgreSQL store's safety properties.

func (*Store) Heartbeat

func (store *Store) Heartbeat(
	ctx context.Context,
	owned lease.Lease,
	ttl time.Duration,
	_ time.Time,
) (lease.Lease, error)

Heartbeat extends a lease when owner and fencing token remain current.

func (*Store) Inspect

func (store *Store) Inspect(ctx context.Context, key string) (lease.Lease, error)

Inspect returns the active lease for a key.

func (*Store) Recover

func (store *Store) Recover(ctx context.Context, key string, fencingToken uint64) error

Recover marks a lease inactive only when its observed token still matches.

func (*Store) Release

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

Release marks a currently owned lease inactive.

Jump to

Keyboard shortcuts

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