Expand description
Cross-process write serialisation per mem.
Every mutation runs reload-before-operation, compares the caller’s
expected_hash, then commits. Those three steps must be one atomic
unit across processes: if a sibling process commits between this
process’s reload and its commit, the compare runs against a snapshot
that is already behind, and a stale write lands over the sibling’s
(a lost update reported as success). The guard below holds an
exclusive OS file lock on the mem’s MemBackend::write_lock_path
for the whole unit, so a second writer blocks until the first has
committed and then reloads, sees the new content, and gets its honest
HASH_MISMATCH.
The lock is reentrant per thread: a mutation that calls another mutation entry point (a batch over single-item paths, a merge over creates) takes the same lock again without blocking on itself. Two threads, or two engines on two threads, still exclude each other, because each takes its own open file description and OS file locks conflict between those even inside one process.
Structs§
- MemWrite
Guard - Held for the duration of one mutation; dropping it releases every lock it took (the OS lock goes when the last nested holder drops).