8000 Clarify storage comments on main by adityamukho · Pull Request #986 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
34 changes: 12 additions & 22 deletions src/storage/backend/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/storage/persistent_facts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/storage/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading
0