pub struct FileHandle { /* private fields */ }Expand description
A handle to a database file capable of positioned reads and writes at page boundaries.
FileHandle is intentionally minimal — it exposes only the
operations the pager (L1) and WAL (L2) need. Higher layers must
never reach past it into std::fs directly; routing every syscall
through this type is how the project keeps Rule 8 enforceable.
Implementations§
Source§impl FileHandle
impl FileHandle
Sourcepub fn try_lock_writer(&self) -> Result<Option<WriterLock>>
pub fn try_lock_writer(&self) -> Result<Option<WriterLock>>
Sourcepub fn lock_writer(&self, timeout: Duration) -> Result<WriterLock>
pub fn lock_writer(&self, timeout: Duration) -> Result<WriterLock>
Acquire the WRITER_LOCK, retrying with bounded exponential
backoff until either acquired or timeout elapses. Returns
Err(Error::Busy { kind: LockKind::Writer }) on timeout.
§Errors
Error::BusywithLockKind::Writeron timeout.Error::Ioon any non-“would-block” syscall failure.
Sourcepub fn lock_reader(&self, timeout: Duration) -> Result<ReaderLock>
pub fn lock_reader(&self, timeout: Duration) -> Result<ReaderLock>
Acquire any one of the 31 reader-lock slots in shared mode,
retrying with bounded backoff until either acquired or
timeout elapses.
The slot is chosen with a per-process round-robin counter so concurrent readers in the same process do not all race for the same byte. Shared locks compose, so falling on the same byte is not a correctness bug — just a hot-spot the spread avoids in practice.
§Errors
Error::BusywithLockKind::Readeron timeout (very rare — shared locks rarely contend).Error::Ioon syscall failure.
Source§impl FileHandle
impl FileHandle
Sourcepub fn open_or_create<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open_or_create<P: AsRef<Path>>(path: P) -> Result<Self>
Sourcepub fn create_new<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn create_new<P: AsRef<Path>>(path: P) -> Result<Self>
Open path for read-write access, failing if the file
already exists (O_CREAT | O_EXCL on POSIX, CREATE_NEW on
Windows). Used by M11 #92 hot-backup to guarantee the
destination is never overwritten.
§Errors
Returns Error::Io if the file already exists, the parent
directory does not exist, or any other syscall failure
occurs.
Trait Implementations§
Source§impl Debug for FileHandle
impl Debug for FileHandle
Source§impl FileBackend for FileHandle
impl FileBackend for FileHandle
Source§fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<()>
fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<()>
FileHandle::read_exact_at. Read moreSource§fn write_all_at(&self, buf: &[u8], offset: u64) -> Result<()>
fn write_all_at(&self, buf: &[u8], offset: u64) -> Result<()>
FileHandle::write_all_at. Read more