Skip to main content

Module lock

Module lock 

Source
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-core instances 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). flock is 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 in crate::writer::atomic_write which 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::WriteOptions fsync flag 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 op while holding an exclusive advisory lock on <vault>/.vaultdb/lock.