Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Lock ¶
type Lock struct { Acquired bool // contains filtered or unexported fields }
Lock is a convenience wrapper around an inner `*consul.Client` with methods to aquire and release a mutually exclusive distributed lock using Consul sessions. This is used by attache-control to ensure that only one Redis Cluster node operation (create, add, remove) happens at once.
func New ¶
New creates a new Consul client, aquires an ephemeral session with that client, and returns a `*Lock` to the caller.
func (*Lock) Acquire ¶
Acquire attempts to obtain a lock for the Consul KV path of `l.key`. Sets `l.Acquired` true on success and false on failure.
func (*Lock) Cleanup ¶
func (l *Lock) Cleanup()
Cleanup stops periodic session renewals used to hold the lock, releases the lock by deleting the key, and destroys the session. Deleting the key and destroying the session only need to be best effort. In the event that either of these calls fail the lock will be released and the session will be destroyed l.sessionTimeout after l.renewChan is closed.