Documentation ¶
Overview ¶
Package distlock provides access to distributed locking mechanisms for the purpose of locking resources across a distributed system. Locker provides the standard interface for locking. To use a specific lock service, you must import a locking implementation from a subdirectory. Note: If faking the interfaces here, you MUST embed the interface in your fakes. Otherwise future changes will break your code.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
LockAcquireTimeoutErr = fmt.Errorf("Timeout trying to acquire lock")
)
Functions ¶
Types ¶
type Handler ¶
type Handler interface { // Lock locks a resource at service location. Implementations will receive // the service without the namespace (whatever://). TryLock(ctx context.Context, service, resource string, options ...LockOption) (Lock, error) // Unlock unlocks a resource at service location. Implemntations will receive // the service without the namespace (whatever://). Release(ctx context.Context, service, resource string, options ...UnlockOption) error }
Handler provides for locking and unlocking resources.
type Info ¶
type Info struct { // LockTime is the time the lock was taken out. LockTime time.Time // ExpireTime is the time the lock expires if not updated. ExpireTime time.Time // Owner is the identitiy of who owns the lock. This is lock type specific. Owner interface{} }
Info provides information about a lock.
type Infoer ¶
type Infoer interface { // Info returns information about a Lock. Info(ctx context.Context, service, resource string) (Info, error) }
Infoer allows getting information about a lock.
type Lock ¶
type Lock struct { // Lost is closed when the lock is lost. Lost chan struct{} // Release can be called to release a lock. Release Releaser }
Lock provides information and operations for a lock that has been taken out.
type LockOption ¶
type LockOption func(o *LockOptions)
LockOption provides an optional argument for locking a resource.
func TTL ¶
func TTL(d time.Duration) LockOption
TTL sets the minimum time the lock will be held. If set below 5 seconds, will panic.
type LockOptions ¶
type LockOptions struct { // TTL is the minimum time to hold the lock. This can be no less than 5 seconds. // TTL only counts as a minimum time in case lock renewal fails. A lock // can expire imediately by calling Release() or Unlocker(). // TTLs have upper limits that can prevent the TTL being set from being implemented. TTL time.Duration }
LockOptions provides options to various Locker implementations. This is not set directly but constructed by using implementations of LockOption.
type Locker ¶
Locker provides access to all functions for interfacing with locks. Not all Locker methods may be provided by all implementations. Only Lock()/Unlock() are guaranteed.
type Reader ¶
type Reader interface { // Read reads the data in the lock into i. Read(ctx context.Context, service, resource string) ([]byte, error) }
Reader allows reading data held in a lock, if the lock can hold data.
type UnlockOption ¶
type UnlockOption func(o *LockOptions)
UnlockOption provides an optional argument for unlocking a resource.
type UnlockOptions ¶
type UnlockOptions struct{}
UnlockOptions provides options to various Locker implementations. This is not set directly but constructed by using implementations of UnlockOption.