Skip to main content

OrderedBatch

Struct OrderedBatch 

Source
pub struct OrderedBatch { /* private fields */ }
Expand description

Tiers of writes separated by barriers, applied in order by apply: within a tier nothing is ordered, across a barrier everything is.

Built the way a store writes: payloads and records staged into the tier they belong to, a barrier wherever a later write will name an earlier one. The batch is a value describing writes without performing them, so — like a ChangeSet — it is equally the answer to “what would this do?”: tiers is the dry-run view, and it is the same sequence apply executes.

use fs_transaction::{OrderedBatch, InMemoryFs, exec::block_on};
use fs_transaction::fs::Durability;
use std::path::Path;

let mut batch = OrderedBatch::new();
batch.create_new("blobs/9f86d081", "payload");
batch.create_new("ops/3a7bd3e2.op", "op-document");
batch.barrier(); // nothing below may be seen without everything above
batch.create_new("revisions/50d858e0.rev", "the record naming both");
block_on(batch.apply(&InMemoryFs::new(), Path::new("store"), Durability::Durable))?;

Implementations§

Source§

impl OrderedBatch

Source

pub fn new() -> Self

An empty batch.

Source

pub fn write( &mut self, path: impl Into<PathBuf>, contents: impl Into<Vec<u8>>, ) -> &mut Self

Stage a write of contents to path (root-relative) in the current tier, creating or atomically replacing the file.

Source

pub fn create_new( &mut self, path: impl Into<PathBuf>, contents: impl Into<Vec<u8>>, ) -> &mut Self

Stage an exclusive create of path (root-relative) holding contents in the current tier. See BatchOp::CreateNew for what an occupied path does to the apply.

Source

pub fn barrier(&mut self) -> &mut Self

Close the current tier: everything staged so far must land before anything staged after this call. Adjacent barriers, and barriers at the edges, cost nothing — an empty tier orders nothing and is skipped.

Source

pub fn tiers(&self) -> &[Vec<BatchOp>]

The staged tiers, in execution order. The dry-run view; a trailing empty tier from a final barrier never appears, since barriers only exist between writes.

Source

pub fn is_empty(&self) -> bool

Whether nothing is staged — apply would be a no-op.

Source

pub fn len(&self) -> usize

The number of staged ops, across every tier.

Source

pub async fn apply<FS: Storage>( &self, fs: &FS, root: &Path, finality: Durability, ) -> Result<()>

Execute every staged op against fs, rooted at root, tier by tier: each tier’s files and freshly-named directories are flushed Ordered before the next tier begins, and the last tier is flushed to finality.

finality is the strength of the batch’s own landing: Durable makes “this call returned” mean “this batch survives a power cut”, Ordered makes it mean only “no crash shows a later tier without an earlier one” — the batch itself may vanish with the crash, wholly or from some barrier on, and for a caller that treats its tree as append-only that is often enough, at the cost of not one Durable request anywhere. (Whether a request is literally a drain is the backend’s affair: without barrier-fsync, StdFs answers even Ordered with the full flush — stronger than asked, as ever.)

On an error the apply stops where it stands and the tree holds a consistent prefix — see the module docs for exactly what that means inside the interrupted tier. Every staged path is clamped to the root before anything is written, on the same terms as ChangeSet::apply.

Trait Implementations§

Source§

impl Clone for OrderedBatch

Source§

fn clone(&self) -> OrderedBatch

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OrderedBatch

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for OrderedBatch

Source§

fn default() -> OrderedBatch

Returns the “default value” for a type. Read more
Source§

impl Eq for OrderedBatch

Source§

impl PartialEq for OrderedBatch

Source§

fn eq(&self, other: &OrderedBatch) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for OrderedBatch

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.