fencing

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func ExitOnLost(label, name string, log *slog.Logger) func(reason string)

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

type Config struct {
	Key   string
	Epoch uint64
}

Config is a fencing token injected by the lord (an epoch + the KV key it stamps).

func ConfigFromEnv

func ConfigFromEnv(epochEnv, keyEnv string) (Config, bool)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL