From eaa70bb255cc17f80206c9822012dd61cf3d16dc Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Thu, 3 Dec 2026 04:35:05 +0530 Subject: [PATCH] Clarify storage comments on main --- src/db.rs | 4 ++-- src/storage/backend/file.rs | 34 ++++++++++++--------------------- src/storage/persistent_facts.rs | 2 +- src/storage/verify.rs | 2 +- 4 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/db.rs b/src/db.rs index ed3e973393..23ef76c3c0 100644 --- a/src/db.rs +++ b/src/db.rs @@ -4121,8 +4121,8 @@ mod tests { assert!(OpenOptions::default().allow_unlocked(true).allow_unlocked); } - /// `allow_unlocked` must not open a door past a live lock. It applies only - /// where the filesystem cannot lock at all. + /// `allow_unlocked` does not override a held lock. It applies only when + /// the filesystem does not support locking. #[test] fn test_allow_unlocked_does_not_bypass_a_live_lock() { let dir = tempfile::tempdir().unwrap(); diff --git a/src/storage/backend/file.rs b/src/storage/backend/file.rs index 61a8d2c8c4..e97ac007ef 100644 --- a/src/storage/backend/file.rs +++ b/src/storage/backend/file.rs @@ -127,19 +127,16 @@ fn already_open_here(path: &Path) -> bool { .unwrap_or(false) } -/// Atomically test-and-set `path` into `OPEN_PATHS`, admitting only callers -/// that do not conflict with a holder: one writer, or any number of readers. +/// Check and record `path` under the same mutex. Allow one writer or +/// any number of readers, but not both at once. /// -/// Used by the `ProceedUnlocked` arm, where there is no kernel lock and this -/// registry is the only thing preventing two handles on one unlockable path -/// (#304). Must be a single critical section: checking with -/// `already_open_here` and inserting afterwards would let two threads both -/// observe "absent" and both proceed. A poisoned mutex yields `false`, so -/// this fails CLOSED rather than admitting a second handle it cannot -/// account for. +/// `ProceedUnlocked` uses this process-local registry when the filesystem +/// cannot provide a lock (#304). Checking and inserting separately would +/// let two conflicting claims both succeed. If the mutex is poisoned, +/// refuse the claim. /// -/// Split out from `open_with` so the race can be exercised directly (#330) -/// instead of needing a genuinely lock-incapable filesystem. +/// This helper lets tests check the race without a filesystem that lacks +/// locks (#330). fn claim_unlocked_path(path: &Path, mode: LockMode) -> bool { OPEN_PATHS .lock() @@ -167,9 +164,8 @@ fn claim_unlocked_path(path: &Path, mode: LockMode) -> bool { /// commonly do) -- can observe `WouldBlock` during that few-microsecond /// window even though no other process is really contending for the file. /// SQLite has the same class of problem and solves it with `busy_timeout`; -/// this is our version, bounded so a database that is genuinely locked by -/// another process still fails -- after paying the full retry budget below, -/// not instantly -- rather than `open` hanging indefinitely. +/// we also limit how long we retry. If another process keeps its lock, +/// `open` returns an error after the retries instead of waiting indefinitely. const LOCK_RETRY_ATTEMPTS: u32 = 10; /// Initial backoff between retries, doubled each attempt up to @@ -294,14 +290,8 @@ impl FileBackend { let mut lock_result = try_lock(); - // Retry a `WouldBlock` with backoff, but ONLY when the conflict might - // be with another process. If this process already has the path - // open, waiting is pointless: we are the only thing that could ever - // release that lock, and we are standing right here not releasing - // it, so every retry would just burn the budget on a certain - // failure. Skipping this check keeps `test_second_open_in_same_process_is_refused` - // fast instead of paying the full retry budget on every same-process - // rejection. + // Retry `WouldBlock` with backoff only if this process does not + // already have the path open. Skip retries for a known local conflict. if matches!(lock_result, Err(std::fs::TryLockError::WouldBlock)) && !already_open_here(&canonical) { diff --git a/src/storage/persistent_facts.rs b/src/storage/persistent_facts.rs index c56768f058..daa9a8002c 100644 --- a/src/storage/persistent_facts.rs +++ b/src/storage/persistent_facts.rs @@ -3884,7 +3884,7 @@ mod tests { // ── size (spec §10.1, §11, #433) ──────────────────────────────────────── /// Check the exact byte bound and report the history fact count for - /// `entities` entities in #433's acceptance shape: + /// `entities` entities in the #433 storage-size test: /// 10 attributes each, 20 % of attributes multi-valued, 10 % retracted and /// re-asserted, written over 10 checkpoints. fn assert_size_per_fact(entities: u64) -> u64 { diff --git a/src/storage/verify.rs b/src/storage/verify.rs index b9a707b5c0..f3b48eac63 100644 --- a/src/storage/verify.rs +++ b/src/storage/verify.rs @@ -316,7 +316,7 @@ impl<'a> Walker<'a> { self.scan_index_with(index, None) } - /// Walk the DICT tree, checking each entry's shape, the two inverse maps, + /// Walk the DICT tree, checking the fields of each entry, the two inverse maps, /// the id counters and every long value. pub fn scan_dict(&mut self) -> DictScan { let next_eid = self.meta.next_eid;