Documentation
¶
Overview ¶
Package lockfile serializes mutating d8 operations across concurrent processes.
Problem ¶
Self-update and plugin install/update rewrite binaries, symlinks, and caches on disk. Two such commands can run concurrently (separate terminals or scripts); without a cross-process lock they would step on each other.
Call sites ¶
Two features share this package (same mechanism, different paths):
- CLI self-update: ~/.deckhouse-cli/cli/install.lock
- Plugin install: <plugins-root>/<name>/install.lock
Usage ¶
Hold the lock for the whole critical section. Do not block waiting - if another process holds a live lock, return a user-facing error:
release, err := lockfile.Acquire(path, staleAfter, onReclaim)
if errors.Is(err, lockfile.ErrLocked) {
return fmt.Errorf("operation already in progress")
}
if err != nil {
return err
}
defer release()
Stale locks ¶
A holder killed with SIGKILL never runs release(). Acquire treats a lock file older than staleAfter as orphaned, reclaims it, and optionally notifies via onReclaim. Callers typically use one hour.
Implementation ¶
- Capture: atomic O_EXCL create (empty file at path; no open fd required).
- Reclaim: rename to a scratch path, verify file identity, then remove. Plain Remove(path) races with a concurrent acquirer and can delete their fresh lock; identity-checked rename closes that hole.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrLocked = errors.New("lock is already held")
ErrLocked means another process holds a live lock at the path. Callers should fail fast with a user-facing message instead of waiting.
Functions ¶
func Acquire ¶
func Acquire(path string, staleAfter time.Duration, onReclaim func(age time.Duration)) (func(), error)
Acquire creates an exclusive lock file at path for the duration of a mutating operation (self-update or plugin install). See package lockfile for call sites, the usage pattern, and reclaim semantics.
- Returns release; call it exactly once when done (typically defer release()).
- Returns ErrLocked if another process already holds a non-stale lock.
- Reclaims a lock older than staleAfter before trying to acquire.
- Calls onReclaim (optional) with the orphan's age after a successful reclaim.
Types ¶
This section is empty.