Class StorePidLock
- Namespace
- Foundation.Data.Doublets.Cli
- Assembly
- Foundation.Data.Doublets.Cli.dll
--lock pid (issue #194): a lock directory, <db>.lock.d,
holding an owner record.
public sealed class StorePidLock : IDisposable
- Inheritance
-
StorePidLock
- Implements
- Inherited Members
Remarks
The directory is built under a private name with its record inside, then
renamed to <db>.lock.d. A rename onto an existing directory
fails, so exactly one process publishes the lock, and a published lock
always has its record. The operating system does not release it when the
owner exits, so a waiter breaks the lock when the record names a process
on this host, in this PID namespace, that is gone. Works where
flock does not, such as on some network file systems. The Rust and
JavaScript clink take the same lock.
Fields
UnownedGrace
A directory without a readable record is treated as abandoned after this long (an owner crashed between creating and renaming it, or another tool made it).
public static readonly TimeSpan UnownedGrace
Field Value
Properties
Path
The lock directory.
public string Path { get; }
Property Value
Methods
BreakStale(string, StoreLockOwner?)
Moves a stale lock aside and removes it. Should a live owner have published a new lock in between, its directory is moved back. A lock that cannot be moved (another waiter moved it first, or the directory is not writable) is left alone: the next attempt sees what became of it.
public static void BreakStale(string directory, StoreLockOwner? expected)
Parameters
directorystringexpectedStoreLockOwner
Dispose()
Removes the lock while it is still ours.
public void Dispose()
LockDirectoryPath(string)
<db>.lock.d.
public static string LockDirectoryPath(string store)
Parameters
storestring
Returns
ReadOwner(string)
The owner record of directory, if it has a readable one.
public static StoreLockOwner? ReadOwner(string directory)
Parameters
directorystring
Returns
StaleReason(string, StoreLockOwner?)
Why the lock in directory may be broken, if it may.
public static string? StaleReason(string directory, StoreLockOwner? owner)
Parameters
directorystringownerStoreLockOwner
Returns
TryAcquire(string, bool, out StoreLockOwner?)
Publishes the lock once, breaking a stale one first. Returns the lock,
or null and in holder the owner of
the lock that holds (null for a directory without a
record).
public static StorePidLock? TryAcquire(string directory, bool trace, out StoreLockOwner? holder)
Parameters
directorystringtraceboolholderStoreLockOwner