Expand description
Vault-scoped exclusive lock used to serialize mutations across processes.
with_vault_lock acquires a flock-style exclusive lock on a hidden
sentinel file at <vault>/.vaultdb/lock for the duration of op. Two
vaultdb-core consumers calling UpdateBuilder::execute (or any other
mutation builder’s execute) on the same vault path will serialize.
§What this protects against
- Two
vaultdb-coreinstances racing on the same file (e.g. the CLI and eduport-tauri running simultaneously, both writing the same record). - Two threads in the same process racing on the same file.
§What this does NOT protect against
- External editors that don’t take this lock (Obsidian, Vim, VS Code).
flockis advisory on Unix and only effective between processes that call it. The mitigation for editor races is mtime-based optimistic concurrency at write time, plus the atomic tempfile+rename incrate::writer::atomic_writewhich guarantees no partial-content reads. Eduport-core is expected to debounce its watcher long enough for atomic writes to settle. - Power loss between write and fsync. Use the
crate::WriteOptionsfsyncflag for durability.
§Layout
<vault>/.vaultdb/
lock # this module's sentinel
rename-journal/ # transactional rename journals (next phase).vaultdb/ is hidden (dotfile) so it doesn’t pollute regular ls output
in the user’s vault.
Functions§
- with_
vault_ lock - Run
opwhile holding an exclusive advisory lock on<vault>/.vaultdb/lock.