Documentation
¶
Overview ¶
Package clusterlock takes the cluster locks a client needs, from the daemon of its node.
A cluster lock serializes, across the nodes, what reads the state of the cluster and changes it on the strength of that reading: two nodes doing it at once both read a state the other is about to change. The node speaking for the cluster grants every lock, for a lease that frees it should its holder die holding it.
A lease is time on a clock, and the nodes and the clients count it on their own: a lease passed from one to another goes as the time left, never as an expiry, so the clocks need not agree on the time, only tick at the same rate. What the lease asks of the holder is to be done before it ends, which nothing but the holder can see to: Deadline is when it ends on the clock of the holder, and WithDeadline a context ending then, for the work the lock protects to stop rather than go on unprotected.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrHeld is the error of a lock another still held at the end of the // wait. ErrHeld = errors.New("cluster lock held") )
Functions ¶
This section is empty.
Types ¶
type Lock ¶
type Lock struct {
Name string
ID string
// Deadline is when the lease ends, on the clock of the holder, no
// later than the node speaking ends it.
Deadline time.Time
// contains filtered or unexported fields
}
Lock is a cluster lock held.
func (*Lock) Release ¶
Release lets the lock go. A lock whose lease ended is not an error to release: it is free, which is what releasing it was for.
func (*Lock) WithDeadline ¶
WithDeadline returns a context ending when the lease does, for the work the lock protects, which is to stop rather than go on once another may hold the lock.
type Options ¶
type Options struct {
// Holder says who holds the lock, for the reader of a listing.
Holder string
// Lease is how long the lock is held unless released before. The
// daemon grants its default when it is zero.
Lease time.Duration
// Wait is how long to wait for the lock while another holds it,
// or while the cluster has no node to grant it.
Wait time.Duration
}
Options says how a lock is asked for.