pub struct WriteTxn<'db, F: FileBackend> { /* private fields */ }Expand description
A write transaction.
Construct via WriteTxn::begin. Holds, for its entire
lifetime:
- A guard on the env’s in-process write-serialization Mutex —
ensures at most one
WriteTxnper env per process. - An optional cross-process
WRITER_LOCKbyte — ensures at most oneWriteTxnacross the cluster of processes that have opened the same file.
WriteTxn::commit finalises the transaction through the pager’s
WAL; WriteTxn::rollback discards pending writes. Dropping an
uncommitted WriteTxn rolls back automatically (and emits an
eprintln! so the caller learns about the silent rollback).
Generic over F: FileBackend (Rule 9: no dyn).
Implementations§
Source§impl<'db, F: FileBackend> WriteTxn<'db, F>
impl<'db, F: FileBackend> WriteTxn<'db, F>
Sourcepub fn begin(env: &'db TxnEnv<F>, timeout: Duration) -> Result<Self>
pub fn begin(env: &'db TxnEnv<F>, timeout: Duration) -> Result<Self>
Begin a new write transaction against env.
Acquires the cross-process WRITER_LOCK (if env.lock_file
is Some) with timeout, then the in-process write-
serialization Mutex. Returns the busy variant of Error
keyed by which lock blocked us.
§Errors
Error::BusywithLockKind::Writerif the cross- process lock did not become available withintimeout.Error::BusywithLockKind::WriterInProcessif another thread in the same process is mid-write.Error::Ioon lock syscall failure.
Sourcepub fn write_page(&self, id: PageId, page: &Page) -> Result<()>
pub fn write_page(&self, id: PageId, page: &Page) -> Result<()>
Write page at id through the pager.
§Errors
Error::InvalidArgumentifidis out of range.Error::Ioon syscall failure.
Sourcepub fn read_page(&self, id: PageId) -> Result<Page>
pub fn read_page(&self, id: PageId) -> Result<Page>
Read id through the pager (sees pending + committed +
main). Used inside a write txn that needs to read-modify-
write a page. Returns an owned Page because the borrow
chain through the pager’s mutex would otherwise tie the
returned reference to the guard.
§Errors
As Pager::read_page.
Sourcepub fn alloc_page(&self) -> Result<PageId>
pub fn alloc_page(&self) -> Result<PageId>
Sourcepub fn lock_pager(&self) -> Result<MutexGuard<'_, Pager<F>>>
pub fn lock_pager(&self) -> Result<MutexGuard<'_, Pager<F>>>
Acquire the pager mutex. Bubble a poisoned mutex up as
WriterInProcess — every txn method that takes the pager
goes through here so the failure mode is uniform.
§Errors
Returns Error::Busy with LockKind::WriterInProcess if
the mutex is poisoned by a previous panic.
Sourcepub fn env(&self) -> &'db TxnEnv<F>
pub fn env(&self) -> &'db TxnEnv<F>
Access the underlying env. Used by callers (e.g. obj
crate) that compose typed handles over the raw txn.