pub struct Db<F: Family, E: Context, C: Contiguous<Item: CodecShared>, I: UnorderedIndex<Value = Location<F>>, H: Hasher, U: Send + Sync> { /* private fields */ }Expand description
An “Any” QMDB implementation generic over ordered/unordered keys and variable/fixed values. Consider using one of the following specialized variants instead, which may be more ergonomic:
Implementations§
Source§impl<F, E, C, I, H, U> Db<F, E, C, I, H, U>
impl<F, E, C, I, H, U> Db<F, E, C, I, H, U>
Sourcepub fn new_batch(&self) -> UnmerkleizedBatch<F, H, U>
pub fn new_batch(&self) -> UnmerkleizedBatch<F, H, U>
Create a new speculative batch of operations with this database as its parent.
Source§impl<F, E, C, I, H, U> Db<F, E, C, I, H, U>
impl<F, E, C, I, H, U> Db<F, E, C, I, H, U>
Sourcepub async fn apply_batch(
&mut self,
batch: Arc<MerkleizedBatch<F, H::Digest, U>>,
) -> Result<Range<Location<F>>, Error<F>>
pub async fn apply_batch( &mut self, batch: Arc<MerkleizedBatch<F, H::Digest, U>>, ) -> Result<Range<Location<F>>, Error<F>>
Apply a batch to the database, returning the range of written operations.
A batch is valid only if every batch applied to the database since this batch’s
ancestor chain was created is an ancestor of this batch. Applying a batch from a
different fork returns crate::qmdb::Error::StaleBatch.
This publishes the batch to the in-memory database state and appends it to the
journal, but does not durably persist it. Call Db::commit or Db::sync to
guarantee durability.
Source§impl<F: Family, E, C, I, H, U> Db<F, E, C, I, H, U>
impl<F: Family, E, C, I, H, U> Db<F, E, C, I, H, U>
Sourcepub fn to_batch(&self) -> Arc<MerkleizedBatch<F, H::Digest, U>>
pub fn to_batch(&self) -> Arc<MerkleizedBatch<F, H::Digest, U>>
Create an initial MerkleizedBatch from the committed DB state.
This is the starting point for building owned batch chains.
Source§impl<F, E, U, C, I, H> Db<F, E, C, I, H, U>where
F: Family,
E: Context,
U: Update,
C: Contiguous<Item = Operation<F, U>>,
I: UnorderedIndex<Value = Location<F>>,
H: Hasher,
Operation<F, U>: Codec,
impl<F, E, U, C, I, H> Db<F, E, C, I, H, U>where
F: Family,
E: Context,
U: Update,
C: Contiguous<Item = Operation<F, U>>,
I: UnorderedIndex<Value = Location<F>>,
H: Hasher,
Operation<F, U>: Codec,
Sourcepub const fn inactivity_floor_loc(&self) -> Location<F>
pub const fn inactivity_floor_loc(&self) -> Location<F>
Return the inactivity floor location. This is the location before which all operations are known to be inactive. Operations before this point can be safely pruned.
Sourcepub async fn get_metadata(&self) -> Result<Option<U::Value>, Error<F>>
pub async fn get_metadata(&self) -> Result<Option<U::Value>, Error<F>>
Get the metadata associated with the last commit.
pub fn root(&self) -> H::Digest
Sourcepub async fn get(&self, key: &U::Key) -> Result<Option<U::Value>, Error<F>>
pub async fn get(&self, key: &U::Key) -> Result<Option<U::Value>, Error<F>>
Get the value of key in the db, or None if it has no value.
Source§impl<F, E, U, C, I, H> Db<F, E, C, I, H, U>
impl<F, E, U, C, I, H> Db<F, E, C, I, H, U>
Sourcepub async fn prune(&mut self, prune_loc: Location<F>) -> Result<(), Error<F>>
pub async fn prune(&mut self, prune_loc: Location<F>) -> Result<(), Error<F>>
Prunes historical operations prior to prune_loc. This does not affect the db’s root or
snapshot.
§Errors
- Returns crate::qmdb::Error::PruneBeyondMinRequired if
prune_loc> inactivity floor. - Returns
crate::merkle::Error::LocationOverflowifprune_loc>crate::merkle::Family::MAX_LEAVES.
pub async fn historical_proof( &self, historical_size: Location<F>, start_loc: Location<F>, max_ops: NonZeroU64, ) -> Result<(Proof<F, H::Digest>, Vec<Operation<F, U>>), Error<F>>
pub async fn proof( &self, loc: Location<F>, max_ops: NonZeroU64, ) -> Result<(Proof<F, H::Digest>, Vec<Operation<F, U>>), Error<F>>
Sourcepub async fn rewind(
&mut self,
size: Location<F>,
) -> Result<Vec<Location<F>>, Error<F>>
pub async fn rewind( &mut self, size: Location<F>, ) -> Result<Vec<Location<F>>, Error<F>>
Rewind the database to size operations, where size is the location of the next append.
This rewinds both the authenticated log and the in-memory snapshot, then restores metadata
(last_commit_loc, inactivity_floor_loc, active_keys) for the new tip commit.
§Errors
Returns an error when:
sizeis not a valid rewind target- the target’s required logical range is not fully retained (for example, the target inactivity floor is pruned)
size - 1is not a commit operation
Any error from this method is fatal for this handle. Rewind may mutate journal state before
all in-memory structures are rebuilt. Callers must drop this database handle after any Err
from rewind and reopen from storage.
Returns the list of locations restored to active state in the snapshot.
A successful rewind is not restart-stable until a subsequent Db::commit or
Db::sync.
Source§impl<F, E, U, C, I, H> Db<F, E, C, I, H, U>
impl<F, E, U, C, I, H> Db<F, E, C, I, H, U>
Source§impl<F: Family, E: Context, K: Array, V: FixedValue, H: Hasher, T: Translator, const P: usize> Db<F, E, Journal<E, Operation<F, Update<K, FixedEncoding<V>>>>, Index<T, Location<F>, P>, H, Update<K, FixedEncoding<V>>>
impl<F: Family, E: Context, K: Array, V: FixedValue, H: Hasher, T: Translator, const P: usize> Db<F, E, Journal<E, Operation<F, Update<K, FixedEncoding<V>>>>, Index<T, Location<F>, P>, H, Update<K, FixedEncoding<V>>>
Source§impl<F: Family, E: Context, K: Array, V: FixedValue, H: Hasher, T: Translator> Db<F, E, Journal<E, Operation<F, Update<K, FixedEncoding<V>>>>, Index<T, Location<F>>, H, Update<K, FixedEncoding<V>>>
impl<F: Family, E: Context, K: Array, V: FixedValue, H: Hasher, T: Translator> Db<F, E, Journal<E, Operation<F, Update<K, FixedEncoding<V>>>>, Index<T, Location<F>>, H, Update<K, FixedEncoding<V>>>
Source§impl<F: Family, E: Context, K: Key, V: VariableValue, H: Hasher, T: Translator, const P: usize> Db<F, E, Journal<E, Operation<F, Update<K, VariableEncoding<V>>>>, Index<T, Location<F>, P>, H, Update<K, VariableEncoding<V>>>
impl<F: Family, E: Context, K: Key, V: VariableValue, H: Hasher, T: Translator, const P: usize> Db<F, E, Journal<E, Operation<F, Update<K, VariableEncoding<V>>>>, Index<T, Location<F>, P>, H, Update<K, VariableEncoding<V>>>
Source§impl<F: Family, E: Context, K: Key, V: VariableValue, H: Hasher, T: Translator> Db<F, E, Journal<E, Operation<F, Update<K, VariableEncoding<V>>>>, Index<T, Location<F>>, H, Update<K, VariableEncoding<V>>>
impl<F: Family, E: Context, K: Key, V: VariableValue, H: Hasher, T: Translator> Db<F, E, Journal<E, Operation<F, Update<K, VariableEncoding<V>>>>, Index<T, Location<F>>, H, Update<K, VariableEncoding<V>>>
Source§impl<F: Family, E: Context, K: Key, V: ValueEncoding, C: Contiguous<Item = Operation<F, K, V>>, I: Index<Value = Location<F>>, H: Hasher> Db<F, E, C, I, H, Update<K, V>>
impl<F: Family, E: Context, K: Key, V: ValueEncoding, C: Contiguous<Item = Operation<F, K, V>>, I: Index<Value = Location<F>>, H: Hasher> Db<F, E, C, I, H, Update<K, V>>
Sourcepub fn span_contains(span_start: &K, span_end: &K, key: &K) -> bool
pub fn span_contains(span_start: &K, span_end: &K, key: &K) -> bool
Whether the span defined by span_start and span_end contains key.
Sourcepub async fn get_span(
&self,
key: &K,
) -> Result<Option<(Location<F>, Update<K, V>)>, Error<F>>
pub async fn get_span( &self, key: &K, ) -> Result<Option<(Location<F>, Update<K, V>)>, Error<F>>
Get the operation that defines the span whose range contains key, or None if the DB is
empty.
Source§impl<F: Family, E: Context, K: Array, V: FixedValue, H: Hasher, T: Translator, const P: usize> Db<F, E, Journal<E, Operation<F, Update<K, FixedEncoding<V>>>>, Index<T, Location<F>, P>, H, Update<K, FixedEncoding<V>>>
impl<F: Family, E: Context, K: Array, V: FixedValue, H: Hasher, T: Translator, const P: usize> Db<F, E, Journal<E, Operation<F, Update<K, FixedEncoding<V>>>>, Index<T, Location<F>, P>, H, Update<K, FixedEncoding<V>>>
Source§impl<F: Family, E: Context, K: Array, V: FixedValue, H: Hasher, T: Translator> Db<F, E, Journal<E, Operation<F, Update<K, FixedEncoding<V>>>>, Index<T, Location<F>>, H, Update<K, FixedEncoding<V>>>
impl<F: Family, E: Context, K: Array, V: FixedValue, H: Hasher, T: Translator> Db<F, E, Journal<E, Operation<F, Update<K, FixedEncoding<V>>>>, Index<T, Location<F>>, H, Update<K, FixedEncoding<V>>>
Source§impl<F: Family, E: Context, K: Key, V: VariableValue, H: Hasher, T: Translator, const P: usize> Db<F, E, Journal<E, Operation<F, Update<K, VariableEncoding<V>>>>, Index<T, Location<F>, P>, H, Update<K, VariableEncoding<V>>>
impl<F: Family, E: Context, K: Key, V: VariableValue, H: Hasher, T: Translator, const P: usize> Db<F, E, Journal<E, Operation<F, Update<K, VariableEncoding<V>>>>, Index<T, Location<F>, P>, H, Update<K, VariableEncoding<V>>>
Source§impl<F: Family, E: Context, K: Key, V: VariableValue, H: Hasher, T: Translator> Db<F, E, Journal<E, Operation<F, Update<K, VariableEncoding<V>>>>, Index<T, Location<F>>, H, Update<K, VariableEncoding<V>>>
impl<F: Family, E: Context, K: Key, V: VariableValue, H: Hasher, T: Translator> Db<F, E, Journal<E, Operation<F, Update<K, VariableEncoding<V>>>>, Index<T, Location<F>>, H, Update<K, VariableEncoding<V>>>
Trait Implementations§
Source§impl<F, E, U, C, I, H> Persistable for Db<F, E, C, I, H, U>
impl<F, E, U, C, I, H> Persistable for Db<F, E, C, I, H, U>
Source§type Error = Error<F>
type Error = Error<F>
Source§async fn commit(&self) -> Result<(), Error<F>>
async fn commit(&self) -> Result<(), Error<F>>
Auto Trait Implementations§
impl<F, E, C, I, H, U> !Freeze for Db<F, E, C, I, H, U>
impl<F, E, C, I, H, U> !RefUnwindSafe for Db<F, E, C, I, H, U>
impl<F, E, C, I, H, U> Send for Db<F, E, C, I, H, U>
impl<F, E, C, I, H, U> Sync for Db<F, E, C, I, H, U>
impl<F, E, C, I, H, U> Unpin for Db<F, E, C, I, H, U>
impl<F, E, C, I, H, U> UnsafeUnpin for Db<F, E, C, I, H, U>where
<C as Contiguous>::Item: Sized,
I: UnsafeUnpin,
C: UnsafeUnpin,
E: UnsafeUnpin,
<H as Hasher>::Digest: UnsafeUnpin,
<E as Storage>::Blob: UnsafeUnpin,
impl<F, E, C, I, H, U> !UnwindSafe for Db<F, E, C, I, H, U>
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