Class StoreLock
- Namespace
- Foundation.Data.Doublets.Cli
- Assembly
- Foundation.Data.Doublets.Cli.dll
Store locking for clink invocations (issue #194).
public sealed class StoreLock : IDisposable
- Inheritance
-
StoreLock
- Implements
- Inherited Members
Remarks
Every invocation reads the store, changes it and saves it back. Two
invocations that overlap must not interleave those steps, or the later
one acts on what the earlier one is about to change. A
StoreLock makes the whole run exclusive for writers and
shared among readers; a waiter gives up with a "store is locked" error
naming the owner once --lock-timeout passes.
--lock flock (the default) takes StoreFileLock on
<db>.lock; --lock pid the directory
<db>.lock.d (StorePidLock), always exclusively;
--lock none nothing. An exclusive flock holder writes its
owner record to <db>.lock.owner and removes it on release, so
that waiters and --lock-status can name it. The Rust and JavaScript
clink take the same locks.
Properties
Paths
The lock files and directories held.
public IReadOnlyList<string> Paths { get; }
Property Value
Methods
Acquire(IReadOnlyList<string>, LockMode, StoreLockOptions)
Locks every store in stores (see
LockOrder(IEnumerable<string>)), waiting up to --lock-timeout for each.
public static StoreLock Acquire(IReadOnlyList<string> stores, LockMode mode, StoreLockOptions options)
Parameters
storesIReadOnlyList<string>modeLockModeoptionsStoreLockOptions
Returns
Exceptions
- StoreLockedException
A store stayed locked.
Dispose()
Releases the locks, the last taken first.
public void Dispose()
LockOrder(IEnumerable<string>)
The stores of one invocation without duplicates, in the order every process locks them: sorted by absolute path. Each keeps the spelling it was given, which is what messages show.
public static IReadOnlyList<string> LockOrder(IEnumerable<string> stores)
Parameters
storesIEnumerable<string>
Returns
OwnerFilePath(string)
<db>.lock.owner: the record of the exclusive flock holder.
public static string OwnerFilePath(string store)
Parameters
storestring
Returns
Status(IReadOnlyList<string>)
--lock-status: one line per store and lock kind, without taking
or creating any lock that is not already there.
public static string Status(IReadOnlyList<string> stores)
Parameters
storesIReadOnlyList<string>