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
impl OrderedBatch
Sourcepub fn write(
&mut self,
path: impl Into<PathBuf>,
contents: impl Into<Vec<u8>>,
) -> &mut Self
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.
Sourcepub fn create_new(
&mut self,
path: impl Into<PathBuf>,
contents: impl Into<Vec<u8>>,
) -> &mut Self
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.
Sourcepub fn barrier(&mut self) -> &mut Self
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.
Sourcepub fn tiers(&self) -> &[Vec<BatchOp>]
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.
Sourcepub async fn apply<FS: Storage>(
&self,
fs: &FS,
root: &Path,
finality: Durability,
) -> Result<()>
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
impl Clone for OrderedBatch
Source§fn clone(&self) -> OrderedBatch
fn clone(&self) -> OrderedBatch
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more