lock

package
v4.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLockNotAcquired is returned when a lock could not be acquired.
	ErrLockNotAcquired = errors.New("lock not acquired")

	// ErrLockLost is returned when a held lock is lost.
	ErrLockLost = errors.New("lock lost")
)

Functions

This section is empty.

Types

type Service

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

Service provides distributed locking capabilities for HA deployments.

func NewService

func NewService(store store.Store, instanceID string) *Service

NewService creates a new distributed lock service.

func (*Service) AcquireLock

func (s *Service) AcquireLock(ctx context.Context, lockName string, ttl time.Duration) (context.Context, context.CancelFunc, error)

AcquireLock attempts to acquire a distributed lock with specified TTL. Returns a context that will be canceled when the lock is lost.

func (*Service) Close

func (s *Service) Close() error

Close shuts down the lock service and releases all held locks.

func (*Service) GetInstanceID

func (s *Service) GetInstanceID() string

GetInstanceID returns the instance ID for this lock service.

func (*Service) GetLockHolder

func (s *Service) GetLockHolder(lockName string) (string, error)

GetLockHolder returns the instance ID that holds the lock, if any.

func (*Service) IsLocked

func (s *Service) IsLocked(lockName string) (bool, error)

IsLocked checks if a lock is currently held by any instance.

func (*Service) ReleaseLock

func (s *Service) ReleaseLock(lockName string) error

ReleaseLock explicitly releases a lock.

func (*Service) TryLock

func (s *Service) TryLock(lockName string, ttl time.Duration) (bool, error)

TryLock attempts to acquire a lock without blocking.

Jump to

Keyboard shortcuts

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