Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNotPostgreSQL is returned when attempting to use PostgreSQL advisory locks // with a non-PostgreSQL database. ErrNotPostgreSQL = errors.New("database is not PostgreSQL; advisory locks are only supported on PostgreSQL") // ErrDatabaseConnectionFailed is returned when the database connection fails. ErrDatabaseConnectionFailed = errors.New("failed to connect to database") // ErrCircuitBreakerOpen is returned when the circuit breaker is open due to // repeated failures, preventing further lock operations. ErrCircuitBreakerOpen = errors.New("circuit breaker open: database is unavailable") // ErrLockAcquisitionFailed is returned when lock acquisition fails after all retries. ErrLockAcquisitionFailed = errors.New("failed to acquire lock after retries") // ErrLockContention is returned when a lock is already held by another process. ErrLockContention = errors.New("lock held by another process") // ErrNoDatabase is returned when no database connection is provided. ErrNoDatabase = errors.New("no database connection provided") )
Functions ¶
Types ¶
type Config ¶
type Config struct {
// KeyPrefix is prepended to all lock keys for namespacing.
// Defaults to "ncps:lock:" if empty.
KeyPrefix string
}
Config holds the configuration for PostgreSQL advisory locks.
type Locker ¶
type Locker struct {
// contains filtered or unexported fields
}
Locker implements lock.Locker using PostgreSQL advisory locks.
func NewLocker ¶
func NewLocker( ctx context.Context, querier database.Querier, cfg Config, retryCfg lock.RetryConfig, allowDegradedMode bool, ) (*Locker, error)
NewLocker creates a new PostgreSQL advisory lock-based locker.
func (*Locker) Lock ¶
Lock acquires an exclusive lock with retry and exponential backoff. NOTE: The `ttl` parameter is ignored. The lock is held until Unlock() is called or the underlying database connection is closed.
type RWLocker ¶
type RWLocker struct {
*Locker
// contains filtered or unexported fields
}
RWLocker implements lock.RWLocker using PostgreSQL advisory locks. It provides both exclusive (write) and shared (read) locking semantics.
Click to show internal directories.
Click to hide internal directories.