pub struct CompactDb<F, E, V, H, C, S: Strategy>where
F: Family,
E: Context,
V: ValueEncoding,
H: Hasher,
Operation<F, V>: EncodeShared + Read<Cfg = C>,
C: Clone + Send + Sync + 'static,{ /* private fields */ }Expand description
A keyless authenticated db that does not retain historical operations after sync.
Implementations§
Source§impl<F, E, V, H, C, S> Db<F, E, V, H, C, S>
impl<F, E, V, H, C, S> Db<F, E, V, H, C, S>
Sourcepub const fn last_commit_loc(&self) -> Location<F>
pub const fn last_commit_loc(&self) -> Location<F>
Return the location of the last commit.
Sourcepub const fn inactivity_floor_loc(&self) -> Location<F>
pub const fn inactivity_floor_loc(&self) -> Location<F>
Return the inactivity floor declared by the last committed batch.
Sourcepub fn size(&self) -> Location<F>
pub fn size(&self) -> Location<F>
Return the location of the next operation appended to this db.
Sourcepub fn get_metadata(&self) -> Option<V::Value>
pub fn get_metadata(&self) -> Option<V::Value>
Get the metadata associated with the last commit.
Sourcepub fn current_target(&self) -> Target<F, H::Digest>
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.
Sourcepub fn new_batch(&self) -> UnmerkleizedBatch<F, H, V, S>
pub fn new_batch(&self) -> UnmerkleizedBatch<F, H, V, S>
Create a new speculative batch of operations with this database as its parent.
Sourcepub fn to_batch(&self) -> Arc<MerkleizedBatch<F, H::Digest, V, S>> ⓘwhere
F: Family,
pub fn to_batch(&self) -> Arc<MerkleizedBatch<F, H::Digest, V, S>> ⓘwhere
F: Family,
Create an owned merkleized batch representing the current committed state.
Sourcepub fn apply_batch(
&mut self,
batch: Arc<MerkleizedBatch<F, H::Digest, V, S>>,
) -> Result<Range<Location<F>>, Error<F>>
pub fn apply_batch( &mut self, batch: Arc<MerkleizedBatch<F, H::Digest, 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
Error::StaleBatchif the batch was created from a stale DB state.Error::FloorRegressedif any unapplied commit’s floor is below the running floor (walking ancestors oldest-first, then the tip).Error::FloorBeyondSizeif any unapplied commit’s floor exceeds its own commit location.
Sourcepub async fn sync(&self) -> Result<(), Error<F>>
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.
Sourcepub async fn commit(&self) -> Result<(), Error<F>>where
F: Family,
pub async fn commit(&self) -> Result<(), Error<F>>where
F: Family,
Durably persist the current db state to disk (alias for Self::sync).
Sourcepub async fn rewind(&mut self) -> Result<(), Error<F>>where
F: Family,
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§impl<F: Family, E: Storage + Clock + Metrics, V: FixedValue, H: Hasher, S: Strategy> Db<F, E, FixedEncoding<V>, H, (), S>
impl<F: Family, E: Storage + Clock + Metrics, V: FixedValue, H: Hasher, S: Strategy> Db<F, E, FixedEncoding<V>, H, (), S>
Trait Implementations§
Source§impl<F, E, V, H, Cfg, S> Database for CompactDb<F, E, V, H, Cfg, S>
impl<F, E, V, H, Cfg, S> Database for CompactDb<F, E, V, H, Cfg, S>
type Family = F
type Op = Operation<F, V>
type Config = Config<Cfg, S>
type Digest = <H as Hasher>::Digest
type Context = E
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>>
async fn from_validated_state( context: Self::Context, config: Self::Config, state: ValidatedState<Self::Family, Self::Op, Self::Digest>, ) -> Result<Self, Error<F>>
Auto Trait Implementations§
impl<F, E, V, H, C, S> !Freeze for Db<F, E, V, H, C, S>
impl<F, E, V, H, C, S> !RefUnwindSafe for Db<F, E, V, H, C, S>
impl<F, E, V, H, C, S> Send for Db<F, E, V, H, C, S>
impl<F, E, V, H, C, S> Sync for Db<F, E, V, H, C, S>
impl<F, E, V, H, C, S> Unpin for Db<F, E, V, H, C, S>
impl<F, E, V, H, C, S> UnsafeUnpin for Db<F, E, V, H, C, S>where
Operation<F, V>: Sized,
C: UnsafeUnpin,
S: UnsafeUnpin,
<V as ValueEncoding>::Value: UnsafeUnpin,
E: UnsafeUnpin,
<H as Hasher>::Digest: UnsafeUnpin,
<E as Storage>::Blob: UnsafeUnpin,
impl<F, E, V, H, C, S> !UnwindSafe for Db<F, E, V, H, C, S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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