pub struct CommFileLock { /* private fields */ }Expand description
Advisory file lock for concurrent access to .acomm files.
Uses fs2 advisory locks so that multiple processes can safely read/write
the same .acomm file without corruption. The sidecar lock file lives at
<data_path>.acomm.lock.
Implementations§
Source§impl CommFileLock
impl CommFileLock
Sourcepub fn acquire(data_path: &Path) -> CommResult<Self>
pub fn acquire(data_path: &Path) -> CommResult<Self>
Acquire an exclusive lock on the .acomm file (blocks until available).
Sourcepub fn try_acquire(data_path: &Path) -> CommResult<Self>
pub fn try_acquire(data_path: &Path) -> CommResult<Self>
Try to acquire an exclusive lock without blocking.
Returns an error immediately if the lock is already held by another process.
Acquire a shared (read) lock on the .acomm file (blocks until
available).
Multiple readers can hold a shared lock simultaneously, but a shared lock blocks exclusive writers.
Sourcepub fn release(self) -> CommResult<()>
pub fn release(self) -> CommResult<()>
Explicitly release the lock and attempt to clean up the lock file.
Sourcepub fn recover_stale(data_path: &Path, max_age_secs: u64) -> CommResult<bool>
pub fn recover_stale(data_path: &Path, max_age_secs: u64) -> CommResult<bool>
Check if the lock file is stale (older than max_age_secs seconds) and
remove it if so.
Returns Ok(true) if a stale lock was recovered, Ok(false) otherwise.