Struct AsyncWtm

Source
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,

Source

pub fn mark_read_comparable_blocking<Q>(&mut self, k: &Q)
where K: Borrow<Q>, Q: ?Sized + Ord,

Marks a key is read.

Source

pub fn mark_conflict_comparable_blocking<Q>(&mut self, k: &Q)
where K: Borrow<Q>, Q: ?Sized + Ord,

Marks a key is conflict.

Source§

impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
where C: CmEquivalent<Key = K>, S: AsyncSpawner,

Source

pub fn mark_read_equivalent_blocking<Q>(&mut self, k: &Q)
where K: Borrow<Q>, Q: ?Sized + Hash + Eq,

Marks a key is read.

Source

pub fn mark_conflict_equivalent_blocking<Q>(&mut self, k: &Q)
where K: Borrow<Q>, Q: ?Sized + Hash + Eq,

Marks a key is conflict.

Source§

impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
where C: Cm<Key = K>, S: AsyncSpawner,

Source

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.

Source

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.

Source

pub fn mark_read_blocking(&mut self, k: &K)

Marks a key is read.

Source

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>
where C: Cm<Key = K>, P: Pwm<Key = K, Value = V>, S: AsyncSpawner,

Source

pub fn rollback_blocking( &mut self, ) -> Result<(), TransactionError<C::Error, P::Error>>

Rolls back the transaction.

Source

pub fn insert_blocking( &mut self, key: K, value: V, ) -> Result<(), TransactionError<C::Error, P::Error>>

Insert a key-value pair to the transaction.

Source

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.

Source

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.

Source

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>
where C: CmComparable<Key = K>, P: PwmEquivalent<Key = K, Value = V>, S: AsyncSpawner,

Source

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>>
where K: Borrow<Q>, Q: ?Sized + Eq + Ord + Hash,

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.
Source

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>>
where K: Borrow<Q>, Q: ?Sized + Eq + Ord + Hash,

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: CmEquivalent<Key = K>, P: PwmComparable<Key = K, Value = V>, S: AsyncSpawner,

Source

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>>
where K: Borrow<Q>, Q: ?Sized + Eq + Ord + Hash,

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.
Source

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>>
where K: Borrow<Q>, Q: ?Sized + Eq + Ord + Hash,

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: CmComparable<Key = K>, P: PwmComparable<Key = K, Value = V>, S: AsyncSpawner,

Source

pub fn contains_key_comparable_blocking<'a, 'b: 'a, Q>( &'a mut self, key: &'b Q, ) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
where K: Borrow<Q>, Q: ?Sized + Ord,

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.
Source

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>>
where K: Borrow<Q>, Q: ?Sized + Ord,

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,

Source

pub const fn version(&self) -> u64

Returns the version of this read transaction.

Source

pub fn pwm(&self) -> Option<&P>

Returns the pending writes manager.

None means the transaction has already been discarded.

Source

pub fn cm(&self) -> Option<&C>

Returns the conflict manager.

None means the transaction has already been discarded.

Source§

impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
where C: AsyncCm<Key = K>, S: AsyncSpawner,

Source

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));
Source

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.

Source

pub async fn mark_read(&mut self, k: &K)

Marks a key is read.

Source

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>
where C: AsyncCm<Key = K>, P: AsyncPwm<Key = K, Value = V>, S: AsyncSpawner,

Source

pub async fn rollback( &mut self, ) -> Result<(), TransactionError<C::Error, P::Error>>

Rolls back the transaction.

Source

pub async fn insert( &mut self, key: K, value: V, ) -> Result<(), TransactionError<C::Error, P::Error>>

Insert a key-value pair to the transaction.

Source

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.

Source

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.

Source

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.

Source

pub async fn commit<F, Fut, O, E>( &mut self, apply: F, ) -> Result<O, WtmError<C::Error, P::Error, E>>
where Fut: Future<Output = Result<O, E>>, F: FnOnce(OneOrMore<Entry<K, V>>) -> Fut, E: Error,

Commits the transaction, following these steps:

  1. If there are no writes, return immediately.

  2. Check if read rows were updated since txn started. If so, return TransactionError::Conflict.

  3. If no conflict, generate a commit timestamp and update written rows’ commit ts.

  4. Batch up all writes, write them to database.

  5. 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>
where C: AsyncCmEquivalent<Key = K>, P: AsyncPwm<Key = K, Value = V>, S: AsyncSpawner,

Source

pub async fn mark_read_equivalent<Q>(&mut self, k: &Q)
where K: Borrow<Q>, Q: ?Sized + Eq + Hash,

Marks a key is read.

Source

pub async fn mark_conflict_equivalent<Q>(&mut self, k: &Q)
where K: Borrow<Q>, Q: ?Sized + Eq + Hash,

Marks a key is conflict.

Source§

impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
where C: AsyncCmEquivalent<Key = K>, P: AsyncPwmEquivalent<Key = K, Value = V>, S: AsyncSpawner,

Source

pub async fn contains_key_equivalent<'a, 'b: 'a, Q>( &'a mut self, key: &'b Q, ) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
where K: Borrow<Q>, Q: ?Sized + Eq + Hash,

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.
Source

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>>
where K: Borrow<Q>, Q: ?Sized + Eq + Hash,

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>, P: AsyncPwmEquivalent<Key = K, Value = V>, S: AsyncSpawner,

Source

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>>
where K: Borrow<Q>, Q: ?Sized + Eq + Ord + Hash,

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.
Source

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>>
where K: Borrow<Q>, Q: ?Sized + Eq + Ord + Hash,

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,

Source

pub async fn mark_read_comparable<Q>(&mut self, k: &Q)
where K: Borrow<Q>, Q: ?Sized + Ord,

Marks a key is read.

Source

pub async fn mark_conflict_comparable<Q>(&mut self, k: &Q)
where K: Borrow<Q>, Q: ?Sized + Ord,

Marks a key is conflict.

Source§

impl<K, V, C, P, S> AsyncWtm<K, V, C, P, S>
where C: AsyncCmComparable<Key = K>, P: AsyncPwmComparable<Key = K, Value = V>, S: AsyncSpawner,

Source

pub async fn contains_key_comparable<'a, 'b: 'a, Q>( &'a mut self, key: &'b Q, ) -> Result<Option<bool>, TransactionError<C::Error, P::Error>>
where K: Borrow<Q>, Q: ?Sized + Ord,

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.
Source

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>>
where K: Borrow<Q>, Q: ?Sized + Ord,

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: AsyncCmEquivalent<Key = K>, P: AsyncPwmComparable<Key = K, Value = V>, S: AsyncSpawner,

Source

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>>
where K: Borrow<Q>, Q: ?Sized + Eq + Ord + Hash,

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.
Source

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>>
where K: Borrow<Q>, Q: ?Sized + Eq + Ord + Hash,

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: AsyncCm<Key = K> + Send, P: AsyncPwm<Key = K, Value = V> + Send, S: AsyncSpawner,

Source

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>>
where K: Send + 'static, V: Send + 'static, Fut: Future<Output = Result<(), E>> + Send, F: FnOnce(OneOrMore<Entry<K, V>>) -> Fut + Send + 'static, CFut: Future<Output = R> + Send + 'static, E: Error + Send, C: 'static, R: Send + 'static,

Acts like commit, but takes a future and a spawner, which gets run via a task to avoid blocking this function. Following these steps:

  1. If there are no writes, return immediately, a new task will be spawned, and future will be invoked.

  2. Check if read rows were updated since txn started. If so, return TransactionError::Conflict.

  3. If no conflict, generate a commit timestamp and update written rows’ commit ts.

  4. Batch up all writes, write them to database.

  5. 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,

Source

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.

Source

pub const fn is_discard(&self) -> bool

Returns true if the transaction is discarded.

Trait Implementations§

Source§

impl<K, V, C, P, S> Drop for AsyncWtm<K, V, C, P, S>
where S: AsyncSpawner,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<K, V, C, P, S> Freeze for AsyncWtm<K, V, C, P, S>
where C: Freeze, P: Freeze, K: Freeze, V: Freeze,

§

impl<K, V, C, P, S> !RefUnwindSafe for AsyncWtm<K, V, C, P, S>

§

impl<K, V, C, P, S> Send for AsyncWtm<K, V, C, P, S>
where C: Send, P: Send, K: Send, V: Send,

§

impl<K, V, C, P, S> Sync for AsyncWtm<K, V, C, P, S>
where C: Sync + Send, P: Sync, K: Sync, V: Sync,

§

impl<K, V, C, P, S> Unpin for AsyncWtm<K, V, C, P, S>
where C: Unpin, P: Unpin, K: Unpin, V: Unpin,

§

impl<K, V, C, P, S> !UnwindSafe for AsyncWtm<K, V, C, P, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more