pub struct Db<E, K, V, T, S = Durable>{
pub inactivity_floor_loc: Location,
pub last_commit_loc: Location,
pub state: S,
/* private fields */
}Expand description
An unauthenticated key-value database based off of an append-only Journal of operations.
Fields§
§inactivity_floor_loc: LocationA location before which all operations are “inactive” (that is, operations before this point are over keys that have been updated by some operation at or after this point).
last_commit_loc: LocationThe location of the last commit operation.
state: SThe state of the store.
Implementations§
Source§impl<E, K, V, T, S> Db<E, K, V, T, S>
impl<E, K, V, T, S> Db<E, K, V, T, S>
Sourcepub async fn get(&self, key: &K) -> Result<Option<V>, Error>
pub async fn get(&self, key: &K) -> Result<Option<V>, Error>
Get the value of key in the db, or None if it has no value.
Sourcepub const fn op_count(&self) -> Location
pub const fn op_count(&self) -> Location
The number of operations that have been applied to this db, including those that have been pruned and those that are not yet committed.
Sourcepub const fn inactivity_floor_loc(&self) -> Location
pub const fn inactivity_floor_loc(&self) -> Location
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<V>, Error>
pub async fn get_metadata(&self) -> Result<Option<V>, Error>
Get the metadata associated with the last commit.
Source§impl<E, K, V, T> Db<E, K, V, T, Durable>
impl<E, K, V, T> Db<E, K, V, T, Durable>
Sourcepub async fn init(
context: E,
cfg: Config<T, <Operation<K, V> as Read>::Cfg>,
) -> Result<Self, Error>
pub async fn init( context: E, cfg: Config<T, <Operation<K, V> as Read>::Cfg>, ) -> Result<Self, Error>
Initializes a new Db with the given configuration.
Sourcepub fn into_dirty(self) -> Db<E, K, V, T, NonDurable>
pub fn into_dirty(self) -> Db<E, K, V, T, NonDurable>
Convert this clean store into its dirty counterpart for making updates.
Source§impl<E, K, V, T> Db<E, K, V, T, NonDurable>
impl<E, K, V, T> Db<E, K, V, T, NonDurable>
Sourcepub async fn update(&mut self, key: K, value: V) -> Result<(), Error>
pub async fn update(&mut self, key: K, value: V) -> Result<(), Error>
Updates key to have value value. The operation is reflected in the snapshot, but will be
subject to rollback until the next successful commit.
Sourcepub async fn create(&mut self, key: K, value: V) -> Result<bool, Error>
pub async fn create(&mut self, key: K, value: V) -> Result<bool, Error>
Creates a new key-value pair in the db. The operation is reflected in the snapshot, but will
be subject to rollback until the next successful commit. Returns true if the key was
created, false if it already existed.
Sourcepub async fn delete(&mut self, key: K) -> Result<bool, Error>
pub async fn delete(&mut self, key: K) -> Result<bool, Error>
Delete key and its value from the db. Deleting a key that already has no value is a no-op.
The operation is reflected in the snapshot, but will be subject to rollback until the next
successful commit. Returns true if the key was deleted, false if it was already inactive.
Sourcepub async fn commit(
self,
metadata: Option<V>,
) -> Result<(Db<E, K, V, T, Durable>, Range<Location>), Error>
pub async fn commit( self, metadata: Option<V>, ) -> Result<(Db<E, K, V, T, Durable>, Range<Location>), Error>
Commit any pending operations to the database, ensuring their durability upon return from
this function. Also raises the inactivity floor according to the schedule. Returns the
(start_loc, end_loc] location range of committed operations. The end of the returned range
includes the commit operation itself, and hence will always be equal to op_count.
Note that even if no operations were added since the last commit, this is a root-state changing operation.
Failures after commit (but before sync or close) may still require reprocessing to
recover the database on restart.
Consumes this dirty store and returns a clean one.
Trait Implementations§
Source§impl<E, K, V, T> Batchable for Db<E, K, V, T, NonDurable>
impl<E, K, V, T> Batchable for Db<E, K, V, T, NonDurable>
Source§impl<E, K, V, T> Deletable for Db<E, K, V, T, NonDurable>
impl<E, K, V, T> Deletable for Db<E, K, V, T, NonDurable>
Source§impl<E, K, V, T, S> LogStore for Db<E, K, V, T, S>
impl<E, K, V, T, S> LogStore for Db<E, K, V, T, S>
type Value = V
Source§fn op_count(&self) -> Location
fn op_count(&self) -> Location
Source§fn inactivity_floor_loc(&self) -> Location
fn inactivity_floor_loc(&self) -> Location
Source§impl<E, K, V, T> Persistable for Db<E, K, V, T, Durable>
impl<E, K, V, T> Persistable for Db<E, K, V, T, Durable>
Source§type Error = Error
type Error = Error
Source§async fn commit(&mut self) -> Result<(), Error>
async fn commit(&mut self) -> Result<(), Error>
Source§impl<E, K, V, T, S> PrunableStore for Db<E, K, V, T, S>
impl<E, K, V, T, S> PrunableStore for Db<E, K, V, T, S>
Source§impl<E, K, V, T> Updatable for Db<E, K, V, T, NonDurable>
impl<E, K, V, T> Updatable for Db<E, K, V, T, NonDurable>
Source§async fn update(
&mut self,
key: Self::Key,
value: Self::Value,
) -> Result<(), Self::Error>
async fn update( &mut self, key: Self::Key, value: Self::Value, ) -> Result<(), Self::Error>
Source§fn create<'a>(
&'a mut self,
key: Self::Key,
value: Self::Value,
) -> impl Future<Output = Result<bool, Self::Error>> + Send + use<'a, Self>where
Self: Send,
fn create<'a>(
&'a mut self,
key: Self::Key,
value: Self::Value,
) -> impl Future<Output = Result<bool, Self::Error>> + Send + use<'a, Self>where
Self: Send,
Auto Trait Implementations§
impl<E, K, V, T, S> Freeze for Db<E, K, V, T, S>
impl<E, K, V, T, S = Durable> !RefUnwindSafe for Db<E, K, V, T, S>
impl<E, K, V, T, S> Send for Db<E, K, V, T, S>
impl<E, K, V, T, S> Sync for Db<E, K, V, T, S>
impl<E, K, V, T, S> Unpin for Db<E, K, V, T, S>
impl<E, K, V, T, S = Durable> !UnwindSafe for Db<E, K, V, T, 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