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
impl WriteScratch
pub fn new( snapshot_ts: u64, node_id_alloc: Arc<AtomicU64>, rel_id_alloc: Arc<AtomicU64>, ) -> Self
pub fn snapshot_ts(&self) -> u64
pub fn take_redo(&mut self) -> Vec<RedoOp>
Sourcepub fn take_redo_with_workspace(
&mut self,
) -> Result<(Vec<RedoOp>, WorkspaceCharge)>
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.
Sourcepub fn redo_since(&self, from: usize) -> Option<Vec<RedoOp>>
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.
Sourcepub fn push_redo(&mut self, op: RedoOp)
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.
Sourcepub fn checkpoint(&self) -> ScratchCheckpoint
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).
Sourcepub fn restore(&mut self, checkpoint: ScratchCheckpoint)
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.
Sourcepub fn mark_statement(&self) -> StatementMark
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.
Sourcepub fn rollback_statement(&mut self, mark: StatementMark) -> Result<()>
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.