Documentation ¶
Index ¶
- Variables
- type FuncMockLock
- type FuncMockLocker
- type GetSession
- type MockLocker
- type Option
- type RuleLock
- type RuleLocker
- func NewCoolOffLocker(expiration time.Duration) RuleLocker
- func NewMapLocker() RuleLocker
- func NewNestedLocker(outer, inner RuleLocker) RuleLocker
- func NewSessionLocker(getSession GetSession, lockTimeout int, closeSession, useTryLock bool) RuleLocker
- func NewV3Locker(cl *v3.Client, lockTimeout int, useTryLock bool) RuleLocker
- func WithMetrics(ruleLocker RuleLocker, name string) RuleLocker
Constants ¶
This section is empty.
Variables ¶
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.
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
FuncMockLocker instances are driven by functions that are provided.
type MockLocker ¶
MockLocker implements the RuleLocker interface.
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
MethodForLock is used to specify the context in which the lock was obtained.
func PatternForLock ¶ added in v1.5.8
PatternForLock is used to specify the pattern that was used to build the lock key for metric tracking purposes.
type RuleLocker ¶
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.