pub struct AsyncWtm<K, V, C, P, S>where
S: AsyncSpawner,{ /* private fields */ }
Expand description
AsyncWtm is used to perform writes to the database. It is created by
calling AsyncTm::write
.
Implementations§
Source§impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>where
C: CmComparable<Key = K>,
S: AsyncSpawner,
impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>where
C: CmComparable<Key = K>,
S: AsyncSpawner,
Source§impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>where
C: CmEquivalent<Key = K>,
S: AsyncSpawner,
impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>where
C: CmEquivalent<Key = K>,
S: AsyncSpawner,
Source§impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>where
C: Cm<Key = K>,
S: AsyncSpawner,
impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>where
C: Cm<Key = K>,
S: AsyncSpawner,
Sourcepub fn blocking_marker(&mut self) -> Option<Marker<'_, C>>
pub fn blocking_marker(&mut self) -> Option<Marker<'_, C>>
This method is used to create a marker for the keys that are operated. It must be used to mark keys when end user is implementing iterators to make sure the transaction manager works correctly.
None
means the transaction has already been discarded.
Sourcepub fn blocking_marker_with_pm(&mut self) -> Option<(Marker<'_, C>, &P)>
pub fn blocking_marker_with_pm(&mut self) -> Option<(Marker<'_, C>, &P)>
Returns a marker for the keys that are operated and the pending writes manager.
None
means the transaction has already been discarded.
As Rust’s borrow checker does not allow to borrow mutable marker and the immutable pending writes manager at the same time, this method is used to solve this problem.
Sourcepub fn mark_read_blocking(&mut self, k: &K)
pub fn mark_read_blocking(&mut self, k: &K)
Marks a key is read.
Sourcepub fn mark_conflict_blocking(&mut self, k: &K)
pub fn mark_conflict_blocking(&mut self, k: &K)
Marks a key is conflict.
Source§impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
Sourcepub fn rollback_blocking(
&mut self,
) -> Result<(), TransactionError<C::Error, P::Error>>
pub fn rollback_blocking( &mut self, ) -> Result<(), TransactionError<C::Error, P::Error>>
Rolls back the transaction.
Sourcepub fn insert_blocking(
&mut self,
key: K,
value: V,
) -> Result<(), TransactionError<C::Error, P::Error>>
pub fn insert_blocking( &mut self, key: K, value: V, ) -> Result<(), TransactionError<C::Error, P::Error>>
Insert a key-value pair to the transaction.
Sourcepub fn remove_blocking(
&mut self,
key: K,
) -> Result<(), TransactionError<C::Error, P::Error>>
pub fn remove_blocking( &mut self, key: K, ) -> Result<(), TransactionError<C::Error, P::Error>>
Removes a key.
This is done by adding a delete marker for the key at commit timestamp. Any reads happening before this timestamp would be unaffected. Any reads after this commit would see the deletion.
Sourcepub fn contains_key_blocking(
&mut self,
key: &K,
) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
pub fn contains_key_blocking( &mut self, key: &K, ) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
Returns true
if the pending writes contains the key.
Sourcepub fn get_blocking<'a, 'b: 'a>(
&'a mut self,
key: &'b K,
) -> Result<Option<EntryRef<'a, K, V>>, TransactionError<C::Error, P::Error>>
pub fn get_blocking<'a, 'b: 'a>( &'a mut self, key: &'b K, ) -> Result<Option<EntryRef<'a, K, V>>, TransactionError<C::Error, P::Error>>
Looks for the key in the pending writes, if such key is not in the pending writes, the end user can read the key from the database.
Source§impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
Sourcepub fn contains_key_comparable_cm_equivalent_pm_blocking<'a, 'b: 'a, Q>(
&'a mut self,
key: &'b Q,
) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
pub fn contains_key_comparable_cm_equivalent_pm_blocking<'a, 'b: 'a, Q>( &'a mut self, key: &'b Q, ) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
Returns true
if the pending writes contains the key.
Ok(None)
: means the key is not in the pending writes, the end user can read the key from the database.Ok(Some(true))
: means the key is in the pending writes.Ok(Some(false))
: means the key is in the pending writes and but is a remove entry.
Sourcepub fn get_comparable_cm_equivalent_pm_blocking<'a, 'b: 'a, Q>(
&'a mut self,
key: &'b Q,
) -> Result<Option<EntryRef<'a, K, V>>, TransactionError<C::Error, P::Error>>
pub fn get_comparable_cm_equivalent_pm_blocking<'a, 'b: 'a, Q>( &'a mut self, key: &'b Q, ) -> Result<Option<EntryRef<'a, K, V>>, TransactionError<C::Error, P::Error>>
Looks for the key in the pending writes, if such key is not in the pending writes, the end user can read the key from the database.
Source§impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
Sourcepub fn contains_key_equivalent_cm_comparable_pm_blocking<'a, 'b: 'a, Q>(
&'a mut self,
key: &'b Q,
) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
pub fn contains_key_equivalent_cm_comparable_pm_blocking<'a, 'b: 'a, Q>( &'a mut self, key: &'b Q, ) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
Returns true
if the pending writes contains the key.
Ok(None)
: means the key is not in the pending writes, the end user can read the key from the database.Ok(Some(true))
: means the key is in the pending writes.Ok(Some(false))
: means the key is in the pending writes and but is a remove entry.
Sourcepub fn get_equivalent_cm_comparable_pm_blocking<'a, 'b: 'a, Q>(
&'a mut self,
key: &'b Q,
) -> Result<Option<EntryRef<'a, K, V>>, TransactionError<C::Error, P::Error>>
pub fn get_equivalent_cm_comparable_pm_blocking<'a, 'b: 'a, Q>( &'a mut self, key: &'b Q, ) -> Result<Option<EntryRef<'a, K, V>>, TransactionError<C::Error, P::Error>>
Looks for the key in the pending writes, if such key is not in the pending writes, the end user can read the key from the database.
Source§impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
Sourcepub fn contains_key_comparable_blocking<'a, 'b: 'a, Q>(
&'a mut self,
key: &'b Q,
) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
pub fn contains_key_comparable_blocking<'a, 'b: 'a, Q>( &'a mut self, key: &'b Q, ) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
Returns true
if the pending writes contains the key.
Ok(None)
: means the key is not in the pending writes, the end user can read the key from the database.Ok(Some(true))
: means the key is in the pending writes.Ok(Some(false))
: means the key is in the pending writes and but is a remove entry.
Sourcepub fn get_comparable_blocking<'a, 'b: 'a, Q>(
&'a mut self,
key: &'b Q,
) -> Result<Option<EntryRef<'a, K, V>>, TransactionError<C::Error, P::Error>>
pub fn get_comparable_blocking<'a, 'b: 'a, Q>( &'a mut self, key: &'b Q, ) -> Result<Option<EntryRef<'a, K, V>>, TransactionError<C::Error, P::Error>>
Looks for the key in the pending writes, if such key is not in the pending writes, the end user can read the key from the database.
Source§impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>where
S: AsyncSpawner,
impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>where
S: AsyncSpawner,
Source§impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>where
C: AsyncCm<Key = K>,
S: AsyncSpawner,
impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>where
C: AsyncCm<Key = K>,
S: AsyncSpawner,
Sourcepub fn marker(&mut self) -> Option<AsyncMarker<'_, C>>
pub fn marker(&mut self) -> Option<AsyncMarker<'_, C>>
This method is used to create a marker for the keys that are operated. It must be used to mark keys when end user is implementing iterators to make sure the transaction manager works correctly.
None
means the transaction has already been discarded.
e.g.
let mut txn = custom_database.write(conflict_manger_opts, pending_manager_opts).unwrap();
let mut marker = txn.marker();
custom_database.iter().map(|k, v| marker.mark(&k));
Sourcepub fn marker_with_pm(&mut self) -> Option<(AsyncMarker<'_, C>, &P)>
pub fn marker_with_pm(&mut self) -> Option<(AsyncMarker<'_, C>, &P)>
Returns a marker for the keys that are operated and the pending writes manager.
None
means the transaction has already been discarded.
As Rust’s borrow checker does not allow to borrow mutable marker and the immutable pending writes manager at the same time, this method is used to solve this problem.
Sourcepub async fn mark_conflict(&mut self, k: &K)
pub async fn mark_conflict(&mut self, k: &K)
Marks a key is conflict.
Source§impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
Sourcepub async fn rollback(
&mut self,
) -> Result<(), TransactionError<C::Error, P::Error>>
pub async fn rollback( &mut self, ) -> Result<(), TransactionError<C::Error, P::Error>>
Rolls back the transaction.
Sourcepub async fn insert(
&mut self,
key: K,
value: V,
) -> Result<(), TransactionError<C::Error, P::Error>>
pub async fn insert( &mut self, key: K, value: V, ) -> Result<(), TransactionError<C::Error, P::Error>>
Insert a key-value pair to the transaction.
Sourcepub async fn remove(
&mut self,
key: K,
) -> Result<(), TransactionError<C::Error, P::Error>>
pub async fn remove( &mut self, key: K, ) -> Result<(), TransactionError<C::Error, P::Error>>
Removes a key.
This is done by adding a delete marker for the key at commit timestamp. Any reads happening before this timestamp would be unaffected. Any reads after this commit would see the deletion.
Sourcepub async fn contains_key(
&mut self,
key: &K,
) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
pub async fn contains_key( &mut self, key: &K, ) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
Returns true
if the pending writes contains the key.
Sourcepub async fn get<'a, 'b: 'a>(
&'a mut self,
key: &'b K,
) -> Result<Option<EntryRef<'a, K, V>>, TransactionError<C::Error, P::Error>>
pub async fn get<'a, 'b: 'a>( &'a mut self, key: &'b K, ) -> Result<Option<EntryRef<'a, K, V>>, TransactionError<C::Error, P::Error>>
Looks for the key in the pending writes, if such key is not in the pending writes, the end user can read the key from the database.
Sourcepub async fn commit<F, Fut, O, E>(
&mut self,
apply: F,
) -> Result<O, WtmError<C::Error, P::Error, E>>
pub async fn commit<F, Fut, O, E>( &mut self, apply: F, ) -> Result<O, WtmError<C::Error, P::Error, E>>
Commits the transaction, following these steps:
-
If there are no writes, return immediately.
-
Check if read rows were updated since txn started. If so, return
TransactionError::Conflict
. -
If no conflict, generate a commit timestamp and update written rows’ commit ts.
-
Batch up all writes, write them to database.
-
If callback is provided, Badger will return immediately after checking for conflicts. Writes to the database will happen in the background. If there is a conflict, an error will be returned and the callback will not run. If there are no conflicts, the callback will be called in the background upon successful completion of writes or any error during write.
Source§impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
Sourcepub async fn contains_key_equivalent<'a, 'b: 'a, Q>(
&'a mut self,
key: &'b Q,
) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
pub async fn contains_key_equivalent<'a, 'b: 'a, Q>( &'a mut self, key: &'b Q, ) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
Returns true
if the pending writes contains the key.
Ok(None)
: means the key is not in the pending writes, the end user can read the key from the database.Ok(Some(true))
: means the key is in the pending writes.Ok(Some(false))
: means the key is in the pending writes and but is a remove entry.
Sourcepub async fn get_equivalent<'a, 'b: 'a, Q>(
&'a mut self,
key: &'b Q,
) -> Result<Option<EntryRef<'a, K, V>>, TransactionError<C::Error, P::Error>>
pub async fn get_equivalent<'a, 'b: 'a, Q>( &'a mut self, key: &'b Q, ) -> Result<Option<EntryRef<'a, K, V>>, TransactionError<C::Error, P::Error>>
Looks for the key in the pending writes, if such key is not in the pending writes, the end user can read the key from the database.
Source§impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
Sourcepub async fn contains_key_comparable_cm_equivalent_pm<'a, 'b: 'a, Q>(
&'a mut self,
key: &'b Q,
) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
pub async fn contains_key_comparable_cm_equivalent_pm<'a, 'b: 'a, Q>( &'a mut self, key: &'b Q, ) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
Returns true
if the pending writes contains the key.
Ok(None)
: means the key is not in the pending writes, the end user can read the key from the database.Ok(Some(true))
: means the key is in the pending writes.Ok(Some(false))
: means the key is in the pending writes and but is a remove entry.
Sourcepub async fn get_comparable_cm_equivalent_pm<'a, 'b: 'a, Q>(
&'a mut self,
key: &'b Q,
) -> Result<Option<EntryRef<'a, K, V>>, TransactionError<C::Error, P::Error>>
pub async fn get_comparable_cm_equivalent_pm<'a, 'b: 'a, Q>( &'a mut self, key: &'b Q, ) -> Result<Option<EntryRef<'a, K, V>>, TransactionError<C::Error, P::Error>>
Looks for the key in the pending writes, if such key is not in the pending writes, the end user can read the key from the database.
Source§impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>where
C: AsyncCmComparable<Key = K>,
S: AsyncSpawner,
impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>where
C: AsyncCmComparable<Key = K>,
S: AsyncSpawner,
Source§impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
Sourcepub async fn contains_key_comparable<'a, 'b: 'a, Q>(
&'a mut self,
key: &'b Q,
) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
pub async fn contains_key_comparable<'a, 'b: 'a, Q>( &'a mut self, key: &'b Q, ) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
Returns true
if the pending writes contains the key.
Ok(None)
: means the key is not in the pending writes, the end user can read the key from the database.Ok(Some(true))
: means the key is in the pending writes.Ok(Some(false))
: means the key is in the pending writes and but is a remove entry.
Sourcepub async fn get_comparable<'a, 'b: 'a, Q>(
&'a mut self,
key: &'b Q,
) -> Result<Option<EntryRef<'a, K, V>>, TransactionError<C::Error, P::Error>>
pub async fn get_comparable<'a, 'b: 'a, Q>( &'a mut self, key: &'b Q, ) -> Result<Option<EntryRef<'a, K, V>>, TransactionError<C::Error, P::Error>>
Looks for the key in the pending writes, if such key is not in the pending writes, the end user can read the key from the database.
Source§impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
Sourcepub async fn contains_key_equivalent_cm_comparable_pm<'a, 'b: 'a, Q>(
&'a mut self,
key: &'b Q,
) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
pub async fn contains_key_equivalent_cm_comparable_pm<'a, 'b: 'a, Q>( &'a mut self, key: &'b Q, ) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
Returns true
if the pending writes contains the key.
Ok(None)
: means the key is not in the pending writes, the end user can read the key from the database.Ok(Some(true))
: means the key is in the pending writes.Ok(Some(false))
: means the key is in the pending writes and but is a remove entry.
Sourcepub async fn get_equivalent_cm_comparable_pm<'a, 'b: 'a, Q>(
&'a mut self,
key: &'b Q,
) -> Result<Option<EntryRef<'a, K, V>>, TransactionError<C::Error, P::Error>>
pub async fn get_equivalent_cm_comparable_pm<'a, 'b: 'a, Q>( &'a mut self, key: &'b Q, ) -> Result<Option<EntryRef<'a, K, V>>, TransactionError<C::Error, P::Error>>
Looks for the key in the pending writes, if such key is not in the pending writes, the end user can read the key from the database.
Source§impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
Sourcepub async fn commit_with_task<F, Fut, CFut, E, R>(
&mut self,
apply: F,
fut: impl FnOnce(Result<(), E>) -> CFut + Send + 'static,
) -> Result<<S as AsyncSpawner>::JoinHandle<R>, WtmError<C::Error, P::Error, E>>
pub async fn commit_with_task<F, Fut, CFut, E, R>( &mut self, apply: F, fut: impl FnOnce(Result<(), E>) -> CFut + Send + 'static, ) -> Result<<S as AsyncSpawner>::JoinHandle<R>, WtmError<C::Error, P::Error, E>>
Acts like commit
, but takes a future and a spawner, which gets run via a
task to avoid blocking this function. Following these steps:
-
If there are no writes, return immediately, a new task will be spawned, and future will be invoked.
-
Check if read rows were updated since txn started. If so, return
TransactionError::Conflict
. -
If no conflict, generate a commit timestamp and update written rows’ commit ts.
-
Batch up all writes, write them to database.
-
Return immediately after checking for conflicts. If there is a conflict, an error will be returned immediately and the no task will be spawned run. If there are no conflicts, a task will be spawned and the future will be called in the background upon successful completion of writes or any error during write.
Source§impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>where
S: AsyncSpawner,
impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>where
S: AsyncSpawner,
Sourcepub fn discard(&mut self)
pub fn discard(&mut self)
Discards a created transaction. This method is very important and must be called. commit*
methods calls this internally.
NOTE: If any operations are run on a discarded transaction, TransactionError::Discard
is returned.
Sourcepub const fn is_discard(&self) -> bool
pub const fn is_discard(&self) -> bool
Returns true if the transaction is discarded.