pub struct WriteBatch { /* private fields */ }Expand description
A write batch that buffers page mutations in memory
Use this to amortize fsync costs across multiple operations:
ⓘ
use sqlitegraph::backend::native::v3::write_batch::WriteBatch;
use sqlitegraph::backend::native::v3::index::IndexPage;
let mut batch = WriteBatch::new();
batch.stage_page(IndexPage::new_leaf(1))?;
batch.stage_page(IndexPage::new_leaf(2))?;
batch.stage_page(IndexPage::new_leaf(3))?;
batch.commit(std::path::Path::new("/tmp/db.graph"))?; // Single fsync for all pagesImplementations§
Source§impl WriteBatch
impl WriteBatch
Sourcepub fn stage_page(&mut self, page: IndexPage) -> NativeResult<()>
pub fn stage_page(&mut self, page: IndexPage) -> NativeResult<()>
Sourcepub fn is_committed(&self) -> bool
pub fn is_committed(&self) -> bool
Check if this batch has been committed
Sourcepub fn commit(self, db_path: &Path) -> NativeResult<()>
pub fn commit(self, db_path: &Path) -> NativeResult<()>
Commit all staged pages to disk in a single operation
This writes all pages and performs exactly ONE fsync. On failure, partial writes may have occurred but pages remain in dirty state (can be retried).
§Arguments
db_path- Path to the database file
§Errors
Returns error if:
- Batch is empty (nothing to commit)
- Batch already committed
- I/O error during write
Trait Implementations§
Source§impl Debug for WriteBatch
impl Debug for WriteBatch
Auto Trait Implementations§
impl Freeze for WriteBatch
impl RefUnwindSafe for WriteBatch
impl Send for WriteBatch
impl Sync for WriteBatch
impl Unpin for WriteBatch
impl UnsafeUnpin for WriteBatch
impl UnwindSafe for WriteBatch
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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 more