lock

package
v1.6.22 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLockedLocally = errors.New("locked locally")

ErrLockedLocally indicates that a local goroutine holds the lock and no attempt will be made to obtain the lock via etcd.

View Source
var ErrNilMutex = errors.New("mutex is nil")

ErrNilMutex indicates that the lock has a nil mutex

Functions

This section is empty.

Types

type FuncMockLock added in v1.5.8

type FuncMockLock struct {
	UnlockF func() error
}

FuncMockLock instances are driven by functions that are provided.

func (FuncMockLock) Unlock added in v1.5.8

func (ml FuncMockLock) Unlock() error

Unlock is a mock implementation of RuleLock.Unlock

type FuncMockLocker added in v1.5.8

type FuncMockLocker struct {
	LockF func(string, ...Option) (RuleLock, error)
}

FuncMockLocker instances are driven by functions that are provided.

func (FuncMockLocker) Lock added in v1.5.8

func (ml FuncMockLocker) Lock(key string, options ...Option) (RuleLock, error)

Lock is a mock implementation of RuleLock.Lock

type GetSession added in v1.5.10

type GetSession func(context.Context) (*v3c.Session, error)

type MockLocker

type MockLocker struct {
	Channel  chan bool
	ErrorMsg *string
}

MockLocker implements the RuleLocker interface.

func (*MockLocker) Lock

func (tlkr *MockLocker) Lock(key string, options ...Option) (RuleLock, error)

type Option

type Option func(lo *options)

Option instances are used to provide optional arguments to the RuleLock.Lock method.

func MethodForLock added in v1.5.8

func MethodForLock(method string) Option

MethodForLock is used to specify the context in which the lock was obtained.

func PatternForLock added in v1.5.8

func PatternForLock(pattern string) Option

PatternForLock is used to specify the pattern that was used to build the lock key for metric tracking purposes.

type RuleLock

type RuleLock interface {
	Unlock() error
}

type RuleLocker

type RuleLocker interface {
	Lock(string, ...Option) (RuleLock, error)
}

func NewCoolOffLocker added in v1.5.10

func NewCoolOffLocker(expiration time.Duration) RuleLocker

NewCoolOffLocker creates a simple locker that will prevent a lock from being obtained if a previous attempt (successful or not) was made within the specified expiration period. It is intended to be used with other lockers to prevent excessive locking using more expensive resources (e.g. etcd). It is theoretically possible for two callers to obtain the same lock, if the cooloff period expires before the first caller releases the lock; therefore this locker needs to be used with a nested locker to prevent two callers from accessing the same protected resource.

func NewMapLocker added in v1.5.10

func NewMapLocker() RuleLocker

func NewNestedLocker added in v1.5.10

func NewNestedLocker(outer, inner RuleLocker) RuleLocker

NewNestedLocker creates a locker that protects the inner locker with an outer locker, so that no unnecessary calls are made to the inner locker when attempting to obtain an unavailable lock.

func NewSessionLocker added in v1.5.10

func NewSessionLocker(getSession GetSession, lockTimeout int, closeSession, useTryLock bool) RuleLocker

NewSessionLocker creates a new locker with the provided session constructor. Note that if closeSession is false, it means that the session provided by getSession will not be closed but instead be reused. In that case the locker must be protected by another locker (for instance an in-memory locker) because locks within the same session are reentrant which means that two goroutines can obtain the same lock.

func NewV3Locker

func NewV3Locker(cl *v3.Client, lockTimeout int, useTryLock bool) RuleLocker

NewV3Locker creates a locker backed by etcd V3.

func WithMetrics added in v1.5.8

func WithMetrics(ruleLocker RuleLocker, name string) RuleLocker

WithMetrics decorates a locker with metrics.

Jump to

Keyboard shortcuts

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