pub trait Delta:
Sized
+ Send
+ Sync
+ 'static {
type Context: Send + Sync + 'static;
type Write: Send + 'static;
type Frozen: Send + Sync + 'static;
type FrozenView: Clone + Send + Sync + 'static;
type ApplyResult: Clone + Send + 'static;
type DeltaView: Clone + Send + Sync + 'static;
// Required methods
fn init(context: Self::Context) -> Self;
fn apply(&mut self, write: Self::Write) -> Result<Self::ApplyResult, String>;
fn estimate_size(&self) -> usize;
fn freeze(self) -> (Self::Frozen, Self::FrozenView, Self::Context);
fn reader(&self) -> Self::DeltaView;
}Expand description
A delta accumulates writes and can produce a frozen snapshot for flushing.
The write coordinator manages a pipeline of three stages, each represented by a different type:
Delta(this trait) — the mutable, in-progress batch. Writes are applied here until the delta is frozen.Frozen— an immutable snapshot of the delta, sent to theFlusherto be persisted to storage.Broadcast— a minimal representation of the flushed state that readers need to update their read image.
Required Associated Types§
Sourcetype Context: Send + Sync + 'static
type Context: Send + Sync + 'static
Mutable state owned by the delta while it accumulates writes.
Returned to the write coordinator on freeze so the
next delta can continue where this one left off.
Sourcetype FrozenView: Clone + Send + Sync + 'static
type FrozenView: Clone + Send + Sync + 'static
Provides an interface for reading the frozen delta. Though Frozen is immutable, we support specifying a distinct read type to allow implementers to provide a different representation or view of flushed state. For example, readers that only allow reading the data flushed to storage can materialize a minimal view of metadata to allow the reader to cheaply update the read image when a new view is broadcast after a flush, while at the same type allowing Frozen to be owned by the coordinator so the contained data doesn’t need to be copied during flush.
Sourcetype ApplyResult: Clone + Send + 'static
type ApplyResult: Clone + Send + 'static
Metadata returned from apply, delivered to the caller
through WriteHandle::wait.
Required Methods§
Sourcefn init(context: Self::Context) -> Self
fn init(context: Self::Context) -> Self
Create a new delta initialized from a snapshot context. The delta takes ownership of the context while it is mutable.
Sourcefn apply(&mut self, write: Self::Write) -> Result<Self::ApplyResult, String>
fn apply(&mut self, write: Self::Write) -> Result<Self::ApplyResult, String>
Apply a write to the delta and return a result for the caller.
Sourcefn estimate_size(&self) -> usize
fn estimate_size(&self) -> usize
Estimate the size of the delta in bytes.
Sourcefn freeze(self) -> (Self::Frozen, Self::FrozenView, Self::Context)
fn freeze(self) -> (Self::Frozen, Self::FrozenView, Self::Context)
Freezes the current delta, creating an image with the delta applied.
Returns the frozen delta and the context (which was owned by the delta).
Implementations should ensure this operation is efficient (e.g., via
copy-on-write or reference counting) since it blocks writes. After this
is complete, the [Flusher::flush] happens on a background thread.
fn reader(&self) -> Self::DeltaView
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.