Documentation ¶
Overview ¶
Package dlm provides an abstraction library for multiple Distributed Lock Manager backends.
Index ¶
Constants ¶
View Source
const ( // DefaultTTL is the TTL of the lock after wich it will be automatically released. DefaultTTL = 15 * time.Second // DefaultWaitTime is how long will we wait to acquire a lock. DefaultWaitTime = 15 * time.Second // DefaultRetryTime is how long will we wait after a failed lock adquisition // before attempting to acquire the lock again. DefaultRetryTime = 5 * time.Second )
Variables ¶
View Source
var ( // ErrLockHeld is returned if we attempt to acquire a lock that is already held. ErrLockHeld = fmt.Errorf("lock already held") // ErrLockNotHeld is returned if we attempt to release a lock that is not held. ErrLockNotHeld = fmt.Errorf("lock not held") // ErrCannotLock is returned when it's not possible to acquire the lock before // the configured wait time ends. ErrCannotLock = fmt.Errorf("timeout while trying to acquire lock") )
Functions ¶
This section is empty.
Types ¶
type DLM ¶
type DLM interface { // NewLock creates a lock for the given key. The returned lock is not held // and must be acquired with a call to .Lock. NewLock(string, *LockOptions) (Locker, error) }
DLM describes a Distributed Lock Manager.
type InMemDLM ¶
type InMemDLM struct {
// contains filtered or unexported fields
}
InMemDLM is a local implementation of a DLM that it's intended to be used during development.
type LockOptions ¶
type LockOptions struct { TTL time.Duration // Optional, defaults to DefaultTTL WaitTime time.Duration // Optional, defaults to DefaultWaitTime RetryTime time.Duration // Optional, defaults to DefaultRetryTime }
LockOptions parameterizes a lock.
func (*LockOptions) WithDefaults ¶
func (lo *LockOptions) WithDefaults() *LockOptions
WithDefaults returns the options with all default values set.
type Locker ¶
type Locker interface { // Key returns the key to be locked. Key() string // Namespace returns the the prefix to be added to the key. If there is not a namespace, // it returns the empty string. Namespace() string // Lock acquires the lock. It fails with error if the lock is already held. Lock() error // Unlock releases the lock. It fails with error if the lock is not currently held. Unlock() error }
Locker describes a lock that can be locked or unlocked.
type Options ¶
type Options struct {
Namespace string // Optional namespace prefixed to each lock key.
}
Options parameterizes a DLM.
type RedisDLM ¶
type RedisDLM struct {
// contains filtered or unexported fields
}
RedisDLM is a DLM that uses Redis as a backend. The implementation is based in the single node algorithm described here: http://redis.io/topics/distlock
Click to show internal directories.
Click to hide internal directories.