postgres

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package postgres is Harbor's V1 Postgres-backed StateStore driver.

It is the multi-node production target for the §9 persistence triad: the third leg, alongside the in-memory reference (Phase 07) and the SQLite driver (Phase 15). Phase 16 inherits `internal/state/conformancetest.Run` verbatim — the suite IS the gate; this driver ships zero new conformance scenarios.

The driver uses `pgx/v5/stdlib` so the rest of Harbor sees a `database/sql.DB`. Parametric queries everywhere; no string concatenation into SQL (AGENTS.md §9). Advisory locks serialise the migration runner so multi-replica boots are race-free.

Internal model:

  • One row per (tenant, user, session, run, kind). The composite primary key is the identity quadruple plus Kind. RunID may be empty (session-scoped state); the column is NOT NULL but accepts the empty string.
  • `bytes` is BYTEA — opaque payload, no JSONB constraint.
  • `event_id` carries a UNIQUE secondary index for LoadByEventID and to defend against duplicate-id leaks under contention.
  • Save is a transactional UPSERT (`INSERT ... ON CONFLICT DO UPDATE`) prefaced by an idempotency probe on `event_id`. When a slot already holds a different EventID, the previous EventID row is implicitly evicted because the slot's row is updated in place.
  • `Close(ctx)` flips an atomic flag BEFORE calling `db.Close()` so subsequent calls fast-fail with `ErrStoreClosed` even while in-flight queries are draining.

Per AGENTS.md §5 (D-025), the driver is safe for concurrent reuse across N goroutines. The conformance suite's `Concurrent_SaveLoad_NoRace` + the local `concurrent_test.go` enforce this under -race.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

New constructs a Postgres-backed state.StateStore against cfg.DSN. Production callers go through state.Open; tests may call New directly to skip the registry.

Errors:

  • empty cfg.DSN
  • sql.Open / migration apply failure
  • advisory-lock acquisition failure (extremely unusual; would indicate severe DB load or operator misconfiguration)

Types

This section is empty.

Jump to

Keyboard shortcuts

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