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 discards historical operations, retaining only a witness for each applied batch.
Implementations§
Source§impl<F, E, K, V, H, C, S> Db<F, E, K, V, H, C, S>
impl<F, E, K, V, H, C, S> Db<F, E, K, 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 target(&self) -> CompactTarget<F, H::Digest>
pub fn target(&self) -> CompactTarget<F, H::Digest>
Return the compact-sync target described by the current witness.
This reflects the most recently applied batch. The target remains non-durable until a
covering Self::commit, Self::sync, or Self::start_sync completes.
Sourcepub fn new_batch(&self) -> UnmerkleizedBatch<F, H, K, V, S>
pub fn new_batch(&self) -> UnmerkleizedBatch<F, H, K, 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, K, V, S>> ⓘwhere
F: Family,
pub fn to_batch(&self) -> Arc<MerkleizedBatch<F, H::Digest, K, V, S>> ⓘwhere
F: Family,
Create an owned merkleized batch representing the current applied state.
Sourcepub fn validate_batch(
&self,
batch: &MerkleizedBatch<F, H::Digest, K, V, S>,
) -> Result<(), Error<F>>
pub fn validate_batch( &self, batch: &MerkleizedBatch<F, H::Digest, K, V, S>, ) -> Result<(), Error<F>>
Check that batch can be applied to the database in its current state, without
applying it.
Self::apply_batch runs the same validation but consumes the database when it
fails; callers that want to reject a bad batch and keep the handle can check first.
Sourcepub async fn apply_batch(
self,
batch: Arc<MerkleizedBatch<F, H::Digest, K, V, S>>,
) -> Result<(Self, Range<Location<F>>), Error<F>>
pub async fn apply_batch( self, batch: Arc<MerkleizedBatch<F, H::Digest, K, V, S>>, ) -> Result<(Self, Range<Location<F>>), Error<F>>
Apply a merkleized batch to the database.
Returns the range of locations written. The state is updated in memory and appended to the
witness journal. Call Self::commit or Self::sync, or await the handle returned by
Self::start_sync, to make the applied state durable.
§Errors
Error::StaleBatchif the batch is detected as stale (seecrate::qmdb::batch_chainfor more details).Error::FloorRegressedif any commit in the chain declares a floor below the previous commit’s floor.Error::FloorBeyondSizeif any commit in the chain declares a floor beyond its own commit location.
Sourcepub async fn start_sync(self) -> Result<(Self, Handle<()>), Error<F>>
pub async fn start_sync(self) -> Result<(Self, Handle<()>), Error<F>>
Begin durably persisting the current db state to disk.
Awaiting the returned Handle provides the same durability guarantee as Self::commit, plus a best-effort attempt to bound the recovery needed on reopen. Use Self::sync to guarantee none is needed. A new sync waits for the prior sync before starting. Failures of the deferred durability work surface on the returned handle and the next durability operation.
Sourcepub async fn commit(self) -> Result<Self, Error<F>>
pub async fn commit(self) -> Result<Self, Error<F>>
Durably persist the current db state to disk. This is faster than Self::sync but
reopen may need to replay the witness journal’s tail to recover.
Sourcepub async fn sync(self) -> Result<Self, Error<F>>
pub async fn sync(self) -> Result<Self, Error<F>>
Durably persist the current db state to disk, also persisting journal metadata to minimize recovery work on reopen.
Sourcepub async fn rewind(self, target: Location<F>) -> Result<Self, Error<F>>where
F: Family,
pub async fn rewind(self, target: Location<F>) -> Result<Self, Error<F>>where
F: Family,
Rewind the db to the applied state with exactly target operations, discarding any
uncommitted batches and any later states. The rewind is made durable before this
method returns.
§Errors
Returns crate::merkle::Error::RewindBeyondHistory (wrapped as Error::Merkle) if
no retained applied state has exactly target operations (never applied, or pruned).
Sourcepub async fn prune(
self,
pruning_boundary: Location<F>,
) -> Result<Self, Error<F>>
pub async fn prune( self, pruning_boundary: Location<F>, ) -> Result<Self, Error<F>>
Drop witnesses for commits with fewer than pruning_boundary operations. Some witness below
the boundary may survive.
Pruning bounds how far back Self::rewind can reach; the current commit’s witness always
survives. The prune is made durable before this method returns.
§Errors
Fails if a compact-sync import has not yet been applied to the witness journal.
Source§impl<F: Family, E: Context, K: Array, V: FixedValue, H: Hasher, S: Strategy> Db<F, E, K, FixedEncoding<V>, H, (), S>
impl<F: Family, E: Context, K: Array, V: FixedValue, H: Hasher, S: Strategy> Db<F, E, K, FixedEncoding<V>, H, (), S>
Trait Implementations§
Source§impl<F, E, K, V, H, Cfg, S> Database for CompactDb<F, E, K, V, H, Cfg, S>
impl<F, E, K, V, H, Cfg, S> Database for CompactDb<F, E, K, V, H, Cfg, S>
type Family = F
type Op = Operation<F, K, V>
type Journal = Memory<F, E, Operation<F, K, V>>
type Config = Config<Cfg, S>
type Digest = <H as Hasher>::Digest
type Context = E
type Hasher = H
Source§async fn from_sync_result(
context: Self::Context,
config: Self::Config,
log: Self::Journal,
pinned_nodes: Option<Vec<Self::Digest>>,
range: NonEmptyRange<Location<F>>,
_apply_batch_size: NonZeroU64,
) -> Result<Self, Error<F>>
async fn from_sync_result( context: Self::Context, config: Self::Config, log: Self::Journal, pinned_nodes: Option<Vec<Self::Digest>>, range: NonEmptyRange<Location<F>>, _apply_batch_size: NonZeroU64, ) -> Result<Self, Error<F>>
Source§async fn persist_sync_result(self) -> Result<Self, Error<F>>
async fn persist_sync_result(self) -> Result<Self, Error<F>>
Source§async fn local_pinned_nodes(
_context: Self::Context,
_config: &Self::Config,
_target: &Target<F, Self::Digest>,
_journal: &Self::Journal,
) -> Result<Option<Vec<Self::Digest>>, Error<F>>
async fn local_pinned_nodes( _context: Self::Context, _config: &Self::Config, _target: &Target<F, Self::Digest>, _journal: &Self::Journal, ) -> Result<Option<Vec<Self::Digest>>, Error<F>>
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> !UnwindSafe 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>
impl<F, E, K, V, H, C, S> Sync for Db<F, E, K, V, H, C, S>
impl<F, E, K, V, H, C, S> Unpin for Db<F, E, K, V, H, C, S>
impl<F, E, K, V, H, C, S> UnsafeUnpin for Db<F, E, K, V, H, C, S>where
Operation<F, K, V>: Sized,
Merkle<F, <H as Hasher>::Digest, S>: UnsafeUnpin,
<H as Hasher>::Digest: UnsafeUnpin,
Location<F>: UnsafeUnpin,
Option<<V as ValueEncoding>::Value>: UnsafeUnpin,
C: UnsafeUnpin,
Store<E, F, <H as Hasher>::Digest>: UnsafeUnpin,
PhantomData<K>: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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