Documentation
¶
Overview ¶
Package postgreslock is a table-based distributed lock that satisfies lock.Provider. Opt-in: importing this package pulls in pgx/v5; the root lock package has no driver dependency.
pg_try_advisory_lock would be faster, but advisory locks have no TTL — a crashed holder keeps the lock until its session ends. With table-based locks the TTL is explicit and enforced by the upsert's WHERE clause: another holder can reclaim an expired row.
Acquire is a single INSERT … ON CONFLICT … DO UPDATE … WHERE … RETURNING statement — atomic in Postgres, so no race window between checking and taking.
Index ¶
Constants ¶
const CreateTableSQL = `` /* 205-byte string literal not displayed */
CreateTableSQL is the schema for the lock table — substitute {table} for the actual name.
const DefaultTable = "fc_locks"
DefaultTable is the lock table name when New is used.
Variables ¶
This section is empty.
Functions ¶
func InitSchema ¶
InitSchema creates DefaultTable. Safe to run repeatedly.
Types ¶
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider is a Postgres-backed implementation of lock.Provider.
Each Acquire mints a unique holder token (random UUID) so Release only deletes locks the caller actually owns — protects against accidental release of a lock that has since been reclaimed by another holder.