lock

package
v0.3.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLockActionRequested = errors.New("lock action already requested")
	ErrLockScheduled       = errors.New("nothing scheduled")
)
View Source
var (
	DefaultRetryDelay     = 10 * time.Millisecond
	DefaultAcquireTimeout = 100 * time.Millisecond
	DefaultTimeout        = 10 * time.Second
)

Functions

This section is empty.

Types

type Lock

type Lock interface {
	// Lock acquires a lock on the key. If the lock is already held, it will block until the lock is acquired or
	// the context fails.
	// Lock returns an error if the context expires or an unrecoverable error occurs when trying to acquire the lock.
	Lock(ctx context.Context) (expired <-chan struct{}, err error)
	// TryLock tries to acquire the lock on the key and reports whether it succeeded.
	// It blocks until at least one attempt was made to acquired the lock, and returns acquired=false and no error
	// if the lock is known to be held by someone else
	TryLock(ctx context.Context) (acquired bool, expired <-chan struct{}, err error)
	// Unlock releases the lock on the key in a non-blocking fashion.
	// It spawns a goroutine that will perform the unlock mechanism until it succeeds or the the lock is
	// expired by the server.
	// It immediately signals to the lock's original expired channel that the lock is released.
	Unlock() error
}

Lock is a distributed lock that can be used to coordinate access to a resource or interest in such a resource. Locks follow the following liveliness & atomicity guarantees to prevent distributed deadlocks and guarantee atomicity in the critical section.

Liveliness A : A lock is always eventually released when the process holding it crashes or exits unexpectedly. Liveliness B : A lock is always eventually released when its backend store is unavailable. Atomicity A : No two processes or threads can hold the same lock at the same time. Atomicity B : Any call to unlock will always eventually release the lock

type LockManager

type LockManager interface {
	// Checks the health of the LockManager backend, conditions are a list of opaque
	// issues that may be present in the backend.
	Health(ctx context.Context) (conditions []string, err error)

	// Instantiates a new Lock instance for the given key, with the given options.
	//
	// Defaults to lock.DefaultOptions if no options are provided.
	NewLock(key string, opts ...LockOption) Lock
}

LockManager is a factory for Lock instances

type LockOption

type LockOption func(o *LockOptions)

func WithTracer added in v0.1.1

func WithTracer(tracer trace.Tracer) LockOption

type LockOptions

type LockOptions struct {
	Tracer trace.Tracer
}

func DefaultLockOptions

func DefaultLockOptions() *LockOptions

func (*LockOptions) Apply

func (o *LockOptions) Apply(opts ...LockOption)

type LockScheduler

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

func NewLockScheduler

func NewLockScheduler() *LockScheduler

func (*LockScheduler) Done

func (l *LockScheduler) Done(f func() error) error

func (*LockScheduler) Schedule

func (l *LockScheduler) Schedule(f func() error) error

type OnceErr

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

Modified sync.Once primitive

func (*OnceErr) Do

func (o *OnceErr) Do(f func() error) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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