table

package
v3.27.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 12 Imported by: 0

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