Documentation
¶
Overview ¶
Package lock implements named distributed locks with fencing tokens.
Every successful acquisition gets a token from one server-wide counter that only goes up. The counter is seeded from the clock (unix microseconds), so tokens keep increasing across restarts as long as the clock doesn't go back. Locks are leader-local: they are neither persisted nor replicated.
Expiry is lazy (checked on every access) plus a timer per lock, which removes it and wakes waiters when it expires.
Index ¶
- type Info
- type Manager
- func (m *Manager) Acquire(name string, ttl time.Duration, owner string, wait time.Duration, ...) (int64, bool)
- func (m *Manager) Extend(name string, token int64, ttl time.Duration) bool
- func (m *Manager) Get(name string) (Info, bool)
- func (m *Manager) Len() int
- func (m *Manager) Release(name string, token int64) bool
- func (m *Manager) TryAcquire(name string, ttl time.Duration, owner string) (int64, bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func (*Manager) Acquire ¶
func (m *Manager) Acquire(name string, ttl time.Duration, owner string, wait time.Duration, cancel ...<-chan struct{}) (int64, bool)
Acquire takes the lock, waiting up to wait for it to be freed. It returns early (false) when cancel is closed.