Documentation
¶
Overview ¶
Package writerlock takes the single-writer lock on a persisted-state directory (CHAOS-103, ADR-0060): an exclusive, non-blocking advisory lock on one well-known file inside the directory, held for as long as the returned Lock is open.
The package answers one question, "does a live process already hold this directory?", and reports one of three verdicts. Acquired: the caller now holds it. Held: a process that is running right now holds it; the kernel releases an flock when its owner dies, so there is no stale-lock case. Undetermined: the question could not be answered (no directory named, the directory or the lock file could not be created, the platform or the filesystem has no advisory locking).
What a verdict means is the caller's decision. Package main refuses to boot on Held unless the operator set an override, and degrades with a notice on Undetermined; none of that is here. The package reads no environment variable, logs nothing, starts no goroutine and has no package-level state. Each Take is independent, and the lock it returns is released only by Close or by the process exiting, so the caller must keep the Lock reachable for as long as it means to be the writer.
It is deliberately not built on internal/storeguard, whose locks are per-attempt markers armed and released around one store open. This lock has the opposite lifetime.
Index ¶
Constants ¶
const FileName = ".culvert-writer.lock"
FileName is the lock file's name inside the directory. It lives in the directory, not beside it, so it travels with a bind mount, a docker volume and an NFS export: the three ways two processes end up sharing one data root. The file is zero bytes and means nothing on its own; the flock is the state.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attempt ¶
type Attempt struct {
// Verdict is the outcome.
Verdict Verdict
// Path is the lock file path that was used. Empty only when no directory
// was named.
Path string
// Cause is the underlying error for an Undetermined verdict, and nil
// otherwise.
Cause error
// Lock is the held lock. Non-nil exactly when Verdict is Acquired.
Lock *Lock
}
Attempt is what Take found.
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock is a held single-writer lock. The flock is tied to the open file description, so the Lock must stay reachable for as long as the caller means to hold it: dropping it would let the descriptor be finalized and the lock released.