pub struct Transaction { /* private fields */ }Expand description
A single transaction
Transactions buffer writes and commit them atomically to the WAL.
Implementations§
Source§impl Transaction
impl Transaction
Sourcepub fn read_page(&mut self, page_id: u32) -> Result<Page, TxError>
pub fn read_page(&mut self, page_id: u32) -> Result<Page, TxError>
Read a page through this transaction
If the page has been written in this transaction, returns the buffered version. Otherwise, reads from the pager.
Sourcepub fn write_page(&mut self, page_id: u32, page: Page) -> Result<(), TxError>
pub fn write_page(&mut self, page_id: u32, page: Page) -> Result<(), TxError>
Write a page through this transaction
The write is buffered and will be committed to the WAL on commit.
Sourcepub fn commit(self) -> Result<(), TxError>
pub fn commit(self) -> Result<(), TxError>
Commit the transaction
Writes all buffered pages to the WAL, then writes a Commit record.
Read-only fast path: when write_set is empty, the
transaction wrote nothing, so there is nothing to make
durable. We skip the WAL append, the wal.sync() (which costs
~100 µs of fsync), and the pager apply loop entirely. The
transaction still transitions to Committed and unregisters
from the manager so subsequent state checks work correctly.
This mirrors postgres’ optimisation in RecordTransactionCommit
(xact.c) which skips XLogFlush when nothing was written.
Trait Implementations§
Source§impl Drop for Transaction
impl Drop for Transaction
Auto Trait Implementations§
impl Freeze for Transaction
impl !RefUnwindSafe for Transaction
impl Send for Transaction
impl Sync for Transaction
impl Unpin for Transaction
impl UnsafeUnpin for Transaction
impl !UnwindSafe for Transaction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request