Expand description
All operating-system contact lives here. Everything above this module is arithmetic over byte arrays and is platform-neutral by construction.
SACRIFICE (Law 4): unbuffered I/O requires offset, length and buffer address to be page-aligned, and forgoes kernel readahead. Bought: the kernel does not keep a second copy of every page, so the cgroup charges only memory we chose.
Structs§
- Aligned
Region - A page-aligned heap region. The buffer pool owns exactly one of these, which satisfies the alignment requirement of unbuffered I/O and the “allocate once, never free” requirement that keeps allocator retention out of the picture.
- IoStats
- One file’s I/O, counted. Per FILE: a global cursor interleaves the data file and the WAL, counting every alternation as a seek and summing both files’ bytes as one – both measured wrong before this existed.
- Locked
- A file whose OS lock is RELEASED BY AN EXPLICIT UNLOCK when this is dropped, not by closing the descriptor.
Enums§
- Barrier
- Which durability barrier a caller wants. Named rather than boolean,
because
truedoes not say what was promised. - IoMode
Traits§
Functions§
- lock_
exclusive - Blocking exclusive lock: waits only for admissions in flight.
- lock_
shared - Blocking shared lock: waits only for an exclusive holder’s critical section (the page-WAL writer’s tail truncation or checkpoint).
- open_
file - Open
path, asking forwant. Returns the mode ACTUALLY obtained. - open_
file_ readonly - 2f: open for a SNAPSHOT READER – read-only at the OS level, so the reader cannot write even by bug, and always Buffered (a reader shares the file with a live writer; O_DIRECT’s alignment contract buys nothing on a cache the writer is also warming).
- open_
file_ writer - Open the database data file for its sole writer and retain an advisory
whole-file lock for exactly as long as the returned
FileIoowns the fd. Readers deliberately useopen_file_readonlyand never contend here. - open_
recovery_ source - Recovery reads through an OS read-only descriptor while excluding writers. No create semantics: a missing source must stay missing.
- sync_
directory - Make a newly created directory’s entry durable using the same portability contract as FileIo::sync_dir (Windows relies on the metadata journal).
- try_
lock_ exclusive - Advisory whole-file lock, non-blocking (2n reader table). Ok(true) = acquired; Ok(false) = held by a live process. The lock dies with the fd – crash-safe by construction. Platform code lives HERE (the 2d rule).
- try_
lock_ shared - Shared counterpart of
try_lock_exclusive: Ok(false) when an exclusive holder is alive. Read-only handles suffice on every supported platform. Used by the page-WAL reader admission (ownership probe, admission gate).