Documentation
¶
Overview ¶
Package postgres implements durable idempotency storage on PostgreSQL using pgx, transaction-scoped advisory locks, row locks, server time, and bounded retention cleanup.
Index ¶
- func GoMigration() (migrations.Migration, error)
- func RecordKeyDigest(key idempotency.Key) []byte
- type Migration
- type Options
- type Store
- func (s *Store) Acquire(ctx context.Context, request idempotency.AcquireRequest) (result idempotency.AcquireResult, err error)
- func (s *Store) Cleanup(ctx context.Context, batch int) (int64, error)
- func (s *Store) Complete(ctx context.Context, request idempotency.CompleteRequest) (idempotency.Record, error)
- func (s *Store) CompleteTx(ctx context.Context, tx pgx.Tx, request idempotency.CompleteRequest) (idempotency.Record, error)
- func (s *Store) Expire(ctx context.Context, key idempotency.Key) (record idempotency.Record, err error)
- func (s *Store) Fail(ctx context.Context, request idempotency.FailRequest) (idempotency.Record, error)
- func (s *Store) Heartbeat(ctx context.Context, request idempotency.HeartbeatRequest) (idempotency.Record, error)
- func (s *Store) Inspect(ctx context.Context, key idempotency.Key) (record idempotency.Record, err error)
- func (s *Store) Release(ctx context.Context, ownership idempotency.Ownership) (idempotency.Record, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GoMigration ¶
func GoMigration() (migrations.Migration, error)
GoMigration returns the schema change in migrations' immutable format.
func RecordKeyDigest ¶
func RecordKeyDigest(key idempotency.Key) []byte
RecordKeyDigest returns the opaque table-key digest used by this adapter.
The returned slice is newly allocated and may be retained or mutated by the caller. Business transactions may use it to lock and validate the same idempotency row before applying a fenced side effect.
Types ¶
type Migration ¶
Migration describes one reversible PostgreSQL schema change.
func SchemaMigration ¶
func SchemaMigration() Migration
SchemaMigration returns the initial durable-record table migration.
type Options ¶
type Options struct {
// Retention keeps terminal and abandoned records available before cleanup.
Retention time.Duration
// OwnerTokens returns unpredictable, globally unique ownership tokens.
OwnerTokens func() (string, error)
}
Options configures record retention and ownership-token generation.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store persists idempotency records through atomic PostgreSQL transactions.
func (*Store) Acquire ¶
func (s *Store) Acquire( ctx context.Context, request idempotency.AcquireRequest, ) (result idempotency.AcquireResult, err error)
Acquire atomically elects an owner or returns the existing semantic outcome.
func (*Store) Complete ¶
func (s *Store) Complete( ctx context.Context, request idempotency.CompleteRequest, ) (idempotency.Record, error)
Complete conditionally persists a current owner's replay result.
func (*Store) CompleteTx ¶
func (s *Store) CompleteTx( ctx context.Context, tx pgx.Tx, request idempotency.CompleteRequest, ) (idempotency.Record, error)
CompleteTx persists completion inside an application-owned pgx transaction. The caller remains responsible for committing or rolling back the transaction.
func (*Store) Expire ¶
func (s *Store) Expire(ctx context.Context, key idempotency.Key) (record idempotency.Record, err error)
Expire marks an elapsed active lease as explicitly expired.
func (*Store) Fail ¶
func (s *Store) Fail( ctx context.Context, request idempotency.FailRequest, ) (idempotency.Record, error)
Fail conditionally persists a current owner's terminal failure.
func (*Store) Heartbeat ¶
func (s *Store) Heartbeat( ctx context.Context, request idempotency.HeartbeatRequest, ) (idempotency.Record, error)
Heartbeat extends a current owner's lease using PostgreSQL time.
func (*Store) Inspect ¶
func (s *Store) Inspect(ctx context.Context, key idempotency.Key) (record idempotency.Record, err error)
Inspect returns the current durable record.
func (*Store) Release ¶
func (s *Store) Release( ctx context.Context, ownership idempotency.Ownership, ) (idempotency.Record, error)
Release abandons a current attempt so a retry can acquire a new fence.