store

package
v3.30.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 7 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 AcquireLockResult

type AcquireLockResult struct {
	LockedBy       string
	LeaseExpiresAt time.Time
}

AcquireLockResult contains the result of a lock acquisition attempt.

type LockStatus

type LockStatus struct {
	Locked         bool
	LockedBy       *string
	LeaseExpiresAt *time.Time
	UpdatedAt      *time.Time
}

LockStatus represents the current status of a lock.

type LockStore

type LockStore interface {
	// CreateLockTable creates the lock table if it doesn't exist. Implementations should ensure
	// that this operation is idempotent.
	CreateLockTable(ctx context.Context, db *sql.DB) error
	// TableExists checks if the lock table exists.
	TableExists(ctx context.Context, db *sql.DB) (bool, error)
	// AcquireLock attempts to acquire a lock for the given lockID.
	AcquireLock(ctx context.Context, db *sql.DB, lockID int64, lockedBy string, leaseDuration time.Duration) (*AcquireLockResult, error)
	// ReleaseLock releases a lock held by the current instance.
	ReleaseLock(ctx context.Context, db *sql.DB, lockID int64, lockedBy string) (*ReleaseLockResult, error)
	// UpdateLease updates the lease expiration time for a lock (heartbeat).
	UpdateLease(ctx context.Context, db *sql.DB, lockID int64, lockedBy string, leaseDuration time.Duration) (*UpdateLeaseResult, error)
	// CheckLockStatus checks the current status of a lock.
	CheckLockStatus(ctx context.Context, db *sql.DB, lockID int64) (*LockStatus, error)
	// CleanupStaleLocks removes any locks that have expired using server time. Returns the list of
	// lock IDs that were cleaned up, if any.
	CleanupStaleLocks(ctx context.Context, db *sql.DB) ([]int64, error)
}

LockStore defines the interface for storing and managing database locks.

func NewMySQL added in v3.28.0

func NewMySQL(tableName string) (LockStore, error)

NewMySQL creates a new MySQL-based LockStore.

func NewPostgres

func NewPostgres(tableName string) (LockStore, error)

NewPostgres creates a new Postgres-based LockStore.

type ReleaseLockResult

type ReleaseLockResult struct {
	LockID int64
}

ReleaseLockResult contains the result of a lock release.

type UpdateLeaseResult

type UpdateLeaseResult struct {
	LeaseExpiresAt time.Time
}

UpdateLeaseResult contains the result of a lease update.

Jump to

Keyboard shortcuts

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