Documentation
¶
Index ¶
- type EtcdRWLock
- func (lock *EtcdRWLock) Close() error
- func (lock *EtcdRWLock) Key() string
- func (lock *EtcdRWLock) RLock(ctx context.Context) error
- func (lock *EtcdRWLock) RUnlock(ctx context.Context) error
- func (lock *EtcdRWLock) RWLock(ctx context.Context) error
- func (lock *EtcdRWLock) RWUnlock(ctx context.Context) error
- type LocalLock
- type RWLock
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EtcdRWLock ¶
type EtcdRWLock struct {
// contains filtered or unexported fields
}
The etcd distributed lock enables you to have a powerful mutual exclusion (mutex) system in with an etcd cluster. You can't use a file lock in distributed environments such as Kubernetes because the Pods are isolated in there own contexts hence would not share the filelock information.
This implementation goes further than a simple mutex, as it implements the readers-writer lock for a writer-preference. Moreover, it implements a circuit breaker under the hood to handle network failures smoothly.
Based upon 'Concurrent Control with "Readers" and "Writers"' by Courtois et al. (1971) DOI: 10.1145/362759.362813
func (*EtcdRWLock) Close ¶
func (lock *EtcdRWLock) Close() error
func (*EtcdRWLock) Key ¶
func (lock *EtcdRWLock) Key() string
type RWLock ¶
type RWLock interface { Key() string // RLock is a reader lock RLock(context.Context) error // RUnlock is a reader unlock RUnlock(context.Context) error // RWLock is a writer lock, thus as priority over readers RWLock(context.Context) error // RWUnlock is a writer unlock RWUnlock(context.Context) error // Close network socket/connections Close() error }
RWLock define an implementation of a readers-writer lock with writer-preference.
Locks should be short-lived and recover from previous states without the need to persist them in memory (for fault-tolerancy and scalability). This imply the context should be passed to the constructor rather than methods.