Documentation
¶
Overview ¶
Package filelock is the one lock on a file across processes: the kernel's lock (flock on unix, LockFileEx on Windows), released by the kernel when its holder dies, with the holder's stamp written inside the file for a refusal to name. Its design and invariants are tla/FileLock.tla. Lock acquisition is exclusive, with waiting or non-blocking forms; release clears the holder note, which names a holder in a refusal but never affects lock decisions.
Its callers, on unix, each the same flock on the same file its earlier binary took, so an old and a new binary exclude each other across an upgrade (each package's *compat*_test.go or TestAnOldBinarysCreateLockKeepsTheNewOneOut): cmd/nova-sandbox (the volume-creation lock, darwin), pkg/swarm (the slot store's lock, behind an in-process turn), internal/tokens (the fold lock), internal/update (the snapshot lock), pkg/friend (the folder deliver adapter's lock) and cmd/nova-config (the loop run's lock). Each creates a fresh lock file itself with the mode it always had. On Windows those packages keep their own locks (an O_EXCL .held file, or byte 0) until a migration in which old and new still exclude each other: this lock is LockFileEx at OffsetHigh 0x80000000. pkg/bus keeps its own lock.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrHeld indicates the lock is currently held by an exclusive holder. ErrHeld = errors.New("lock held") // ErrBusy indicates the lock could not be acquired because only shared askers were present. // It is distinct from ErrHeld and does not wrap it. ErrBusy = errors.New("lock busy") // ErrTimeout indicates waiting for the lock timed out. ErrTimeout = errors.New("lock timeout") // ErrNotSupported indicates that filelock is not supported on the current platform. ErrNotSupported = errors.New("filelock: locking is not supported on this platform") )
Functions ¶
This section is empty.
Types ¶
type FileLock ¶
type FileLock struct {
// contains filtered or unexported fields
}
FileLock represents an acquired, open file lock.
func Lock ¶
Lock acquires the exclusive file lock on path, waiting up to timeout with jittered backoff.
The lockfile path must be dedicated to filelock: taking an exclusive lock on an existing regular file truncates it when writing the holder stamp. The file is created if absent and is never removed.
type HeldError ¶
HeldError describes a refusal because another process holds the lock, or a timeout occurred while waiting for the lock.
func AsHeldError ¶
AsHeldError reports whether err is a *HeldError.
type Stamp ¶
Stamp records diagnostic details of who holds the lock: PID, host, start time, and label.
func ReadStamp ¶
ReadStamp reads and parses the Stamp from path without acquiring the lock. It opens with O_RDONLY and does not block on FIFOs.