pub struct Store<E, K, V, T>{ /* private fields */ }Expand description
An unauthenticated key-value database based off of an append-only VJournal of operations.
Implementations§
Source§impl<E, K, V, T> Store<E, K, V, T>
impl<E, K, V, T> Store<E, K, V, T>
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>
Sourcepub async fn get(&self, key: &K) -> Result<Option<V>, Error>
pub async fn get(&self, key: &K) -> Result<Option<V>, Error>
Gets the value associated with the given key in the store.
If the key does not exist, returns Ok(None).
Sourcepub async fn get_loc(&self, loc: Location) -> Result<Option<V>, Error>
pub async fn get_loc(&self, loc: Location) -> Result<Option<V>, Error>
Get the value of the operation with location loc in the db. Returns
Error::OperationPruned if loc precedes the oldest retained location. The location is
otherwise assumed valid.
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 the value associated with the given key in the store.
The operation is immediately visible in the snapshot for subsequent queries, but remains uncommitted until Store::commit is called. Uncommitted operations will be rolled back if the store is closed without committing.
Sourcepub async fn upsert(
&mut self,
key: K,
update: impl FnOnce(&mut V),
) -> Result<(), Error>where
V: Default,
pub async fn upsert(
&mut self,
key: K,
update: impl FnOnce(&mut V),
) -> Result<(), Error>where
V: Default,
Updates the value associated with the given key in the store, inserting a default value if the key does not already exist.
The operation is immediately visible in the snapshot for subsequent queries, but remains uncommitted until Store::commit is called. Uncommitted operations will be rolled back if the store is closed without committing.
Sourcepub async fn delete(&mut self, key: K) -> Result<(), Error>
pub async fn delete(&mut self, key: K) -> Result<(), Error>
Deletes the value associated with the given key in the store. If the key has no value, the operation is a no-op.
Sourcepub async fn commit(&mut self, metadata: Option<V>) -> Result<(), Error>
pub async fn commit(&mut self, metadata: Option<V>) -> Result<(), 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. Caller can
associate an arbitrary metadata value with the commit.
Failures after commit (but before sync or close) may still require reprocessing to
recover the database on restart.
Sourcepub async fn sync(&mut self) -> Result<(), Error>
pub async fn sync(&mut self) -> Result<(), Error>
Sync all database state to disk. While this isn’t necessary to ensure durability of committed operations, periodic invocation may reduce memory usage and the time required to recover the database on restart.
Sourcepub async fn prune(&mut self, target_prune_loc: Location) -> Result<(), Error>
pub async fn prune(&mut self, target_prune_loc: Location) -> Result<(), Error>
Prune historical operations that are behind the inactivity floor. This does not affect the state root.
§Panics
Panics if target_prune_loc is greater than the inactivity floor.
Sourcepub async fn get_metadata(&self) -> Result<Option<(Location, Option<V>)>, Error>
pub async fn get_metadata(&self) -> Result<Option<(Location, Option<V>)>, Error>
Get the location and metadata associated with the last commit, or None if no commit has been made.
§Errors
Returns Error if there is some underlying storage failure.
Sourcepub async fn close(self) -> Result<(), Error>
pub async fn close(self) -> Result<(), Error>
Closes the store. Any uncommitted operations will be lost if they have not been committed via Store::commit.
Sourcepub async fn destroy(self) -> Result<(), Error>
pub async fn destroy(self) -> Result<(), Error>
Destroys the store permanently, removing all persistent data associated with it.
§Warning
This operation is irreversible. Do not call this method unless you are sure you want to delete all data associated with this store permanently!
Sourcepub fn op_count(&self) -> Location
pub fn op_count(&self) -> Location
Returns the number of operations that have been applied to the store, including those that are not yet committed.
Sourcepub fn inactivity_floor_loc(&self) -> Location
pub fn inactivity_floor_loc(&self) -> Location
Return the inactivity floor location. This is the location before which all operations are known to be inactive.
Trait Implementations§
Source§impl<E, K, V, T> Db<E, K, V, T> for Store<E, K, V, T>
impl<E, K, V, T> Db<E, K, V, T> for Store<E, K, V, T>
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§async fn get(&self, key: &K) -> Result<Option<V>, Error>
async fn get(&self, key: &K) -> Result<Option<V>, Error>
key in the db, or None if it has no value.Source§async fn update(&mut self, key: K, value: V) -> Result<(), Error>
async fn update(&mut self, key: K, value: V) -> Result<(), Error>
key to have value value. The operation is reflected in the snapshot, but will be
subject to rollback until the next successful commit.Source§async fn delete(&mut self, key: K) -> Result<(), Error>
async fn delete(&mut self, key: K) -> Result<(), Error>
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.Source§async fn commit(&mut self) -> Result<(), Error>
async fn commit(&mut self) -> Result<(), Error>
Source§async fn sync(&mut self) -> Result<(), Error>
async fn sync(&mut self) -> Result<(), Error>
Source§async fn prune(&mut self, target_prune_loc: Location) -> Result<(), Error>
async fn prune(&mut self, target_prune_loc: Location) -> Result<(), Error>
target_prune_loc. This does not affect the db’s root
or current snapshot.Auto Trait Implementations§
impl<E, K, V, T> Freeze for Store<E, K, V, T>
impl<E, K, V, T> !RefUnwindSafe for Store<E, K, V, T>
impl<E, K, V, T> Send for Store<E, K, V, T>
impl<E, K, V, T> Sync for Store<E, K, V, T>
impl<E, K, V, T> Unpin for Store<E, K, V, T>
impl<E, K, V, T> !UnwindSafe for Store<E, K, V, T>
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