Skip to main content

CompactDb

Struct CompactDb 

Source
pub struct CompactDb<F, E, K, V, H, C, S: Strategy>
where F: Family, E: Context, K: Key, V: ValueEncoding, H: Hasher, Operation<F, K, V>: EncodeShared + Read<Cfg = C>, C: Clone + Send + Sync + 'static,
{ /* private fields */ }
Expand description

An immutable authenticated db that does not retain historical operations after sync.

Implementations§

Source§

impl<F, E, K, V, H, C, S: Strategy> Db<F, E, K, V, H, C, S>
where F: Family, E: Context, K: Key, V: ValueEncoding, H: Hasher, Operation<F, K, V>: EncodeShared + Read<Cfg = C>, C: Clone + Send + Sync + 'static,

Source

pub fn root(&self) -> H::Digest
where F: Family,

Return the root of the db.

Source

pub const fn strategy(&self) -> &S

Return a reference to the merkleization strategy.

Source

pub const fn last_commit_loc(&self) -> Location<F>

Return the location of the last commit.

Source

pub const fn inactivity_floor_loc(&self) -> Location<F>

Return the inactivity floor declared by the last committed batch.

Source

pub fn size(&self) -> Location<F>

Return the location of the next operation appended to this db.

Source

pub fn get_metadata(&self) -> Option<V::Value>

Get the metadata associated with the last commit.

Source

pub fn current_target(&self) -> Target<F, H::Digest>

Return the compact-sync target described by the current witness.

This reflects the last state for which both frontier and witness were durably captured, which may lag behind live in-memory mutations until Self::sync is called.

Source

pub fn new_batch(&self) -> UnmerkleizedBatch<F, H, K, V, S>

Create a new speculative batch of operations with this database as its parent.

Source

pub fn to_batch(&self) -> Arc<MerkleizedBatch<F, H::Digest, K, V, S>>
where F: Family,

Create an owned merkleized batch representing the current committed state.

Source

pub fn apply_batch( &mut self, batch: Arc<MerkleizedBatch<F, H::Digest, K, V, S>>, ) -> Result<Range<Location<F>>, Error<F>>

Apply a merkleized batch to the database.

Returns the range of locations written. The state is updated in memory only; call Self::sync or Self::commit to persist.

§Errors
Source

pub async fn sync(&self) -> Result<(), Error<F>>

Durably persist the current db state to disk.

This is the point at which in-memory mutations become servable via compact sync. The compact Merkle frontier and last-commit witness are written into the same slot, reusing the cached witness when the current state has already been persisted.

Source

pub async fn commit(&self) -> Result<(), Error<F>>
where F: Family,

Durably persist the current db state to disk (alias for Self::sync).

Source

pub async fn rewind(&mut self) -> Result<(), Error<F>>
where F: Family,

Restore the state as of the sync before the most recent one.

Discards any uncommitted batches, flips the db back to the previous persisted state, and reloads the cached commit metadata and inactivity floor from that slot.

Callers must drop any Arc<MerkleizedBatch> merkleized against state that this rewind discards. Self::apply_batch validates batches by size only: a discarded-branch batch will usually trip the size-mismatch check, but if the db later regrows to the same size along an alternate branch, the stale batch becomes admissible again and applying it will corrupt the committed root. Batches merkleized against the state this rewind restores to (for example, a batch built before an advance that is then discarded by the rewind) remain compatible and apply cleanly.

§Errors

Returns crate::merkle::Error::RewindBeyondHistory (wrapped as Error::Merkle) if no prior state exists — either no sync has occurred yet, or the previous state was already consumed by a rewind with no intervening sync.

Any error from this method is fatal for this handle. The Merkle layer may have already flipped its generation pointer and rebuilt its in-memory state before a later step (e.g. reloading the cached commit metadata or inactivity floor) fails, leaving this Db’s in-memory fields out of sync with the persisted slot. Callers must drop this handle after any Err from rewind and reopen from storage.

Source

pub async fn destroy(self) -> Result<(), Error<F>>

Destroy all persisted state associated with this database.

Source§

impl<F: Family, E: Storage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, S: Strategy> Db<F, E, K, FixedEncoding<V>, H, (), S>

Source

pub async fn init(context: E, cfg: CompactConfig<S>) -> Result<Self, Error<F>>

Returns a CompactDb initialized from cfg.

Source§

impl<F: Family, E: Storage + Clock + Metrics, K: Key, V: VariableValue, H: Hasher, C: Clone + Send + Sync + 'static, S: Strategy> Db<F, E, K, VariableEncoding<V>, H, C, S>
where Operation<F, K, V>: Read<Cfg = C>,

Source

pub async fn init( context: E, cfg: CompactConfig<C, S>, ) -> Result<Self, Error<F>>

Returns a CompactDb initialized from cfg.

Trait Implementations§

Source§

impl<F, E, K, V, H, Cfg, S> Database for CompactDb<F, E, K, V, H, Cfg, S>
where F: Family, E: Context, K: Key, V: ValueEncoding, H: Hasher, S: Strategy, Operation<F, K, V>: EncodeShared + Read<Cfg = Cfg>, Cfg: Clone + Send + Sync + 'static,

Source§

type Family = F

Source§

type Op = Operation<F, K, V>

Source§

type Config = Config<Cfg, S>

Source§

type Digest = <H as Hasher>::Digest

Source§

type Context = E

Source§

type Hasher = H

Source§

async fn from_validated_state( context: Self::Context, config: Self::Config, state: ValidatedState<Self::Family, Self::Op, Self::Digest>, ) -> Result<Self, Error<F>>

Build a database from authenticated state in memory. Read more
Source§

fn inactivity_floor(op: &Self::Op) -> Option<Location<Self::Family>>

Return the inactivity floor if the operation is a commit.
Source§

fn root(&self) -> Self::Digest

Get the root digest for final verification.
Source§

async fn persist_compact_state(&self) -> Result<(), Error<F>>

Persist the compact-initialized state once the caller has verified its root.

Auto Trait Implementations§

§

impl<F, E, K, V, H, C, S> !Freeze for Db<F, E, K, V, H, C, S>

§

impl<F, E, K, V, H, C, S> !RefUnwindSafe for Db<F, E, K, V, H, C, S>

§

impl<F, E, K, V, H, C, S> Send for Db<F, E, K, V, H, C, S>
where Operation<F, K, V>: Sized,

§

impl<F, E, K, V, H, C, S> Sync for Db<F, E, K, V, H, C, S>
where Operation<F, K, V>: Sized,

§

impl<F, E, K, V, H, C, S> Unpin for Db<F, E, K, V, H, C, S>
where Operation<F, K, V>: Sized, C: Unpin, S: Unpin, <V as ValueEncoding>::Value: Unpin, K: Unpin, F: Unpin, E: Unpin, <H as Hasher>::Digest: Unpin, <E as Storage>::Blob: Unpin,

§

impl<F, E, K, V, H, C, S> UnsafeUnpin for Db<F, E, K, V, H, C, S>

§

impl<F, E, K, V, H, C, S> !UnwindSafe for Db<F, E, K, V, H, C, S>

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,