Documentation
¶
Overview ¶
Package singleton implements a distributed lock over NATS KV - so that a thrall with scope="singleton" runs only once across the whole cluster, even when several lords run against it (multi-node). The lock rests on two primitives:
- kv.Create = atomic "create only if it does not exist" (CAS on non-existence) -> acquire
- bucket TTL = when the holder stops renewing (crashed), the key expires -> failover
Index ¶
Constants ¶
const ( Bucket = "aether_singletons" // TTL is the lock's time-to-live: the key expires when the holder stops renewing it, // which triggers failover. The thrall derives its fencing lease window from the same value. TTL = 3 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock is a held lock for a single name; it keeps the revision for CAS renewal.
func (*Lock) Epoch ¶
Epoch returns the fencing token of this held lock. It is injected into the singleton thrall so the thrall can verify, independently of the lord, that it still holds the lock.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager opens the KV bucket of locks.
func (*Manager) TryAcquire ¶
TryAcquire attempts to acquire the lock atomically. ok=false means another lord holds it. The create revision doubles as the fencing epoch handed out to the thrall.