pub struct DataDirLock { /* private fields */ }Expand description
RAII guard. Drop releases the kernel-level flock automatically (by closing the underlying file descriptor) and removes the pidfile.
Implementations§
Source§impl DataDirLock
impl DataDirLock
Source§impl DataDirLock
impl DataDirLock
Sourcepub fn acquire(data_dir: &Path) -> Result<Self>
pub fn acquire(data_dir: &Path) -> Result<Self>
Acquire the writer lock on data_dir. Returns immediately with
Error::LockHeld if another process holds it.
Sourcepub fn acquire_or_break_stale(data_dir: &Path) -> Result<Self>
pub fn acquire_or_break_stale(data_dir: &Path) -> Result<Self>
Like Self::acquire, but if the lock appears stale (pidfile names
a PID that’s no longer alive), reclaim it. Refuses to break a lock
held by a live named holder.
Strategy: re-attempt Self::acquire on the existing lockfile inode.
When the named holder really has died, the kernel released its flock
and the second attempt succeeds. When something else is genuinely
holding the flock — an inherited FD outliving the named holder, or a
PID-reuse race that briefly makes the pidfile lie — the second
attempt still returns LockHeld and we surface
Error::StaleLockBreakRefused.
We deliberately do NOT unlink the lockfile and acquire on a fresh inode: that path can leave two processes each holding “the lock” on separate inodes if the original inode’s flock is still held, violating invariant #1 (at most one process holds the writer lock).