Skip to main content

WriteScratch

Struct WriteScratch 

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

Per-attempt write buffer. The shared Graph is not mutated until apply_redo.

workspace is not cloned. A clone keeps the created entities and takes its own reservation once, at clone time, so dropping the original releases the original reservation once.

Implementations§

Source§

impl WriteScratch

Source

pub fn new( snapshot_ts: u64, node_id_alloc: Arc<AtomicU64>, rel_id_alloc: Arc<AtomicU64>, ) -> Self

Source

pub fn snapshot_ts(&self) -> u64

Source

pub fn take_redo(&mut self) -> Vec<RedoOp>

Source

pub fn take_redo_with_workspace( &mut self, ) -> Result<(Vec<RedoOp>, WorkspaceCharge)>

Drain the redo and hand its live workspace reservation to the caller.

The scratch’s execution allocation is still represented by the redo vector while WAL commit serializes and applies it. The caller holds this charge through that boundary, then drops it once the commit has either been rejected or acknowledged.

Source

pub fn redo_since(&self, from: usize) -> Option<Vec<RedoOp>>

The redo ops at or after from: what the statements run since that position appended. None when from is past the end — the log shrank under the caller’s cursor, which the caller refuses rather than reading as nothing. Reads without draining, so a caller bounding the transaction’s prospective commit measures the same ops that commit will.

Source

pub fn push_redo(&mut self, op: RedoOp)

The one funnel every write goes through: post the op to the lazy equality indexes, account the ADR-0309 update counters, then append it to the redo log.

Source

pub fn checkpoint(&self) -> ScratchCheckpoint

Pre-batch state for CALL { … } IN TRANSACTIONS. The rollback image is the whole scratch state as of here, in three parts: the per-batch maps (the one embedded [PerBatchState] capture), the statement-spanning [StatementState] (its ADR-0309 counters and its applied-change count, so a rolled-back batch restores both), and the redo log positionally — a cursor, not a second op vec — so per-batch capture is O(1) in the accumulated ops (a by-value copy would be quadratic on the no-sink path, where each batch re-captures over an ever-growing log). Id allocators stay on the live scratch so a rolled-back batch does not hand the same id out again; they are not part of the image.

The pipelined write batch does not use this: its per-statement rollback is Self::mark_statement, which the batch’s CREATE-only eligibility rule makes exact at O(statement) instead of O(batch).

Source

pub fn restore(&mut self, checkpoint: ScratchCheckpoint)

Roll back to a captured Self::checkpoint: the per-batch state and the statement-spanning state restores as one, and the redo log truncates to its captured position (the live log’s ops stay with the live log). Because the applied-change count rides the restored [StatementState], a batch that rolled back applied nothing — a statement whose every batch failed is still a zero-effect write (ADR-0402 Decision 2) — and the restore never has to derive that from how many ops the truncation dropped.

Source

pub fn mark_statement(&self) -> StatementMark

Pre-statement mark for the pipelined write batch (ADR-0642): the redo cursor and the statement-spanning state as of the statement’s entry. Cheap by construction — O(statement), never a copy of the batch image — because the batch admits only CREATE-only statements, so the entries a failed statement can have added are exactly the ids its own [StatementState::created_nodes] / created_rels recorded at the redo funnel.

Source

pub fn rollback_statement(&mut self, mark: StatementMark) -> Result<()>

Roll back to a Self::mark_statement: drop the entities the failed statement created, truncate the redo to the mark’s cursor and put the statement-spanning state back. The batch’s other entries — the earlier statements’ rows — are untouched, so a failing batched statement loses only its own writes.

The lazy equality indexes keep their postings for the dropped ids: they are additions-only supersets every seek re-verifies on its view (ADR-0172 §3), which is the same state a delete leaves behind.

A redo this mark cannot invert is refused, not half-applied: the statement’s entries stay where they are and the caller fails the batch, so a rollback that could not finish never leaves partial writes to be committed with the batch — the durability lie the batch’s whole failure contract exists to avoid.

Trait Implementations§

Source§

impl Clone for WriteScratch

Source§

fn clone(&self) -> Self

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

Auto Trait Implementations§

§

impl Forget for WriteScratch

§

impl Freeze for WriteScratch

§

impl Move for WriteScratch

§

impl RefUnwindSafe for WriteScratch

§

impl Send for WriteScratch
where RawTable<(i64, Node)>: Send, RawTable<(String, HashMap<String, HashMap<GroupKey, HashSet<i64>>>)>: Send, Arc<Vec<String>>: Send, Arc<PropertyMap>: Send, RawTable<(i64, Relationship)>: Send, RawVecInner: Send, RawTable<(i64, ())>: Send, RawTable<(i64, Vec<i64>)>: Send, Arc<Mutex<HashMap<u32, LabelMemo>>>: Send, RawTable<(String, i32)>: Send, BoxRaw<RedoOp>: Send, Arc<Atomic<u64>>: Send,

§

impl Sync for WriteScratch
where RawTable<(i64, Node)>: Sync, RawTable<(String, HashMap<String, HashMap<GroupKey, HashSet<i64>>>)>: Sync, Arc<Vec<String>>: Sync, Arc<PropertyMap>: Sync, RawTable<(i64, Relationship)>: Sync, RawVecInner: Sync, RawTable<(i64, ())>: Sync, RawTable<(i64, Vec<i64>)>: Sync, Arc<Mutex<HashMap<u32, LabelMemo>>>: Sync, RawTable<(String, i32)>: Sync, BoxRaw<RedoOp>: Sync, Arc<Atomic<u64>>: Sync,

§

impl Unpin for WriteScratch

§

impl UnsafeUnpin for WriteScratch

§

impl UnwindSafe for WriteScratch

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V