Documentation
¶
Overview ¶
Package fencing holds the self-fencing loop shared by processes the lord spawns: a thrall or an edge server periodically verifies a KV token (a singleton lock or the lord's liveness lease) and terminates itself when the token is lost, so no process outlives the authority that owns it. The loop is deliberately transport-agnostic - it takes a verify closure - so both the singleton lock and the lord lease reuse it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExitOnLost ¶
ExitOnLost is the production onLost: it logs the loss and terminates the process. Tests inject a channel-based onLost instead, so Loop stays verifiable without exiting.
func Loop ¶
func Loop(label string, verify func() (bool, error), interval, lease time.Duration, log *slog.Logger, stop <-chan struct{}, onLost func(reason string))
Loop runs the self-fencing loop until stop is closed. On each tick it calls verify(): a confirmed loss (verify returns false - the epoch was superseded or the key is gone) calls onLost at once. When verify cannot conclude (an error, e.g. the KV is unreachable) it calls onLost only once the lease has fully elapsed with no confirmation, bounding the window in which the fenced condition may already have failed. onLost is expected to terminate the process; label prefixes the logs.
Types ¶
type Config ¶
Config is a fencing token injected by the lord (an epoch + the KV key it stamps).
func ConfigFromEnv ¶
ConfigFromEnv reads a token from the given epoch/key environment variables. ok is false when the process was not handed this kind of token (e.g. a non-singleton thrall, or one started without a lord), in which case the corresponding fencing loop must not run.