Skip to main content

Delta

Trait Delta 

Source
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 the Flusher to be persisted to storage.
  • Broadcast — a minimal representation of the flushed state that readers need to update their read image.

Required Associated Types§

Source

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.

Source

type Write: Send + 'static

A single write operation applied via apply.

Source

type Frozen: Send + Sync + 'static

Immutable snapshot produced by freeze, consumed by the Flusher to persist the batch to storage.

Source

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.

Source

type ApplyResult: Clone + Send + 'static

Metadata returned from apply, delivered to the caller through WriteHandle::wait.

Source

type DeltaView: Clone + Send + Sync + 'static

Provides an interface for reading the current delta. The specific read API is up to the delta implementation. It is up to the implementation to provide the APIs required for a given database, including support for snapshot isolation

Required Methods§

Source

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.

Source

fn apply(&mut self, write: Self::Write) -> Result<Self::ApplyResult, String>

Apply a write to the delta and return a result for the caller.

Source

fn estimate_size(&self) -> usize

Estimate the size of the delta in bytes.

Source

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_delta happens on a background thread.

Source

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.

Implementors§