table

package
v3.30.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	TableName         string
	LockID            int64
	LeaseDuration     time.Duration
	HeartbeatInterval time.Duration
	LockTimeout       ProbeConfig
	UnlockTimeout     ProbeConfig

	// Optional logger for lock operations
	Logger *slog.Logger

	// Optional custom retry policy for database errors
	RetryPolicy RetryPolicyFunc
}

Config holds configuration for table locker.

type Locker

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

Locker implements table-based locking for databases. This implementation is safe for concurrent use by multiple goroutines.

func New

func New(lockStore store.LockStore, cfg Config) *Locker

New creates a new table-based locker.

func (*Locker) Lock

func (l *Locker) Lock(ctx context.Context, db *sql.DB) error

Lock acquires the database lock. This method is safe for concurrent use - the mutex is held until Unlock() is called. Only one goroutine can hold the lock at a time across the entire lifecycle.

func (*Locker) Unlock

func (l *Locker) Unlock(ctx context.Context, db *sql.DB) error

Unlock releases the database lock. This method must be called exactly once after a successful Lock() call.

type ProbeConfig

type ProbeConfig struct {
	IntervalDuration time.Duration
	FailureThreshold uint64
}

ProbeConfig holds retry configuration.

type RetryPolicyFunc

type RetryPolicyFunc func(err error) bool

RetryPolicyFunc inspects an error and returns whether the caller should retry the operation. This allows for database-specific error handling without hardcoding driver-specific logic.

Jump to

Keyboard shortcuts

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