locks

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 21 Imported by: ? 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

View Source
var ErrLockHeld = errors.New("lock is held by another owner")

Functions

This section is empty.

Types

type HeldLock

type HeldLock struct {
	Key        string
	Backend    string
	Holder     string
	AcquiredAt time.Time
	ExpiresAt  time.Time
}

type Inspector

type Inspector interface {
	Snapshot(ctx context.Context) ([]HeldLock, error)
	Stats() LockStats
	ForceRelease(ctx context.Context, key string) (bool, error)
}

type Lease

type Lease interface {
	Release(ctx context.Context) error
}

type LocalManager

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

func NewLocalManager

func NewLocalManager() *LocalManager

func (*LocalManager) Acquire

func (m *LocalManager) Acquire(ctx context.Context, key string) (Lease, error)

func (*LocalManager) Close

func (m *LocalManager) Close() error

func (*LocalManager) ForceRelease

func (m *LocalManager) ForceRelease(_ context.Context, key string) (bool, error)

func (*LocalManager) SetWaitTimeout

func (m *LocalManager) SetWaitTimeout(d time.Duration)

func (*LocalManager) Snapshot

func (m *LocalManager) Snapshot(_ context.Context) ([]HeldLock, error)

func (*LocalManager) Stats

func (c *LocalManager) Stats() LockStats

type LockStats

type LockStats struct {
	Acquired    uint64
	Timeouts    uint64
	Cancelled   uint64
	Errors      uint64
	LostLeases  uint64
	RenewErrors uint64
	WaitP50Ms   *int64
	WaitP95Ms   *int64
}

type Manager

type Manager interface {
	Acquire(ctx context.Context, key string) (Lease, error)

	Close() error
}

type NATSManager

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

func NewNATSManager

func NewNATSManager(ctx context.Context, js jetstream.JetStream, nodeID string, ttl, queueStale time.Duration, logger *zap.Logger) (*NATSManager, error)

func (*NATSManager) Acquire

func (m *NATSManager) Acquire(ctx context.Context, key string) (Lease, error)

func (*NATSManager) Close

func (m *NATSManager) Close() error

func (*NATSManager) FenceToken

func (m *NATSManager) FenceToken(key string) (uint64, bool)

func (*NATSManager) ForceRelease

func (m *NATSManager) ForceRelease(ctx context.Context, key string) (bool, error)

func (*NATSManager) SetWaitTimeout

func (m *NATSManager) SetWaitTimeout(d time.Duration)

func (*NATSManager) Snapshot

func (m *NATSManager) Snapshot(ctx context.Context) ([]HeldLock, error)

func (*NATSManager) Stats

func (c *NATSManager) Stats() LockStats

type RedisManager

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

func NewRedisManagerWithOptions

func NewRedisManagerWithOptions(opts RedisOptions, logger *zap.Logger) (*RedisManager, error)

func (*RedisManager) Acquire

func (m *RedisManager) Acquire(ctx context.Context, key string) (Lease, error)

func (*RedisManager) Close

func (m *RedisManager) Close() error

func (*RedisManager) ForceRelease

func (m *RedisManager) ForceRelease(ctx context.Context, key string) (bool, error)

func (*RedisManager) SetWaitTimeout

func (m *RedisManager) SetWaitTimeout(d time.Duration)

func (*RedisManager) Snapshot

func (m *RedisManager) Snapshot(ctx context.Context) ([]HeldLock, error)

func (*RedisManager) Stats

func (c *RedisManager) Stats() LockStats

type RedisOptions

type RedisOptions struct {
	Addr         string
	Password     string
	PoolSize     int
	MinIdleConns int
	TLSConfig    *tls.Config
}

Jump to

Keyboard shortcuts

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