Struct mz_stash::TableTransaction
source · [−]pub struct TableTransaction<K, V> {
pub(crate) initial: BTreeMap<K, V>,
pub(crate) pending: BTreeMap<K, Option<V>>,
pub(crate) uniqueness_violation: fn(a: &V, b: &V) -> bool,
}
Expand description
TableTransaction emulates some features of a typical SQL transaction over
table for a StashCollection
.
It supports:
- uniqueness constraints
- transactional reads and writes (including read-your-writes before commit)
K
is the primary key type. Multiple entries with the same key are disallowed.
V
is the an arbitrary value type.
To finalize, add the results of TableTransaction::pending()
to an
AppendBatch
.
Fields
initial: BTreeMap<K, V>
pending: BTreeMap<K, Option<V>>
uniqueness_violation: fn(a: &V, b: &V) -> bool
Implementations
sourceimpl<K, V> TableTransaction<K, V> where
K: Ord + Eq + Hash + Clone,
V: Ord + Clone,
impl<K, V> TableTransaction<K, V> where
K: Ord + Eq + Hash + Clone,
V: Ord + Clone,
sourcepub fn new(
initial: BTreeMap<K, V>,
uniqueness_violation: fn(a: &V, b: &V) -> bool
) -> Self
pub fn new(
initial: BTreeMap<K, V>,
uniqueness_violation: fn(a: &V, b: &V) -> bool
) -> Self
Create a new TableTransaction with initial data.
uniqueness_violation
is a function whether there is a
uniqueness violation among two values.
sourcepub fn pending(self) -> Vec<(K, V, Diff)>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn pending(self) -> Vec<(K, V, Diff)>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Consumes and returns the pending changes and their diffs. Diff
is
guaranteed to be 1 or -1.
pub(crate) fn verify(&self) -> Result<(), StashError>
sourcepub fn for_values<F: FnMut(&K, &V)>(&self, f: F)
pub fn for_values<F: FnMut(&K, &V)>(&self, f: F)
Iterates over the items viewable in the current transaction in arbitrary order.
sourcepub(crate) fn for_values_mut<F: FnMut(&mut BTreeMap<K, Option<V>>, &K, &V)>(
&mut self,
f: F
)
pub(crate) fn for_values_mut<F: FnMut(&mut BTreeMap<K, Option<V>>, &K, &V)>(
&mut self,
f: F
)
Iterates over the items viewable in the current transaction, and provides a Vec where additional pending items can be inserted, which will be appended to current pending items. Does not verify unqiueness.
sourcepub fn insert(&mut self, k: K, v: V) -> Result<(), ()>
pub fn insert(&mut self, k: K, v: V) -> Result<(), ()>
Inserts a new k,v pair.
Returns an error if the uniqueness check failed or the key already exists.
Auto Trait Implementations
impl<K, V> RefUnwindSafe for TableTransaction<K, V> where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for TableTransaction<K, V> where
K: Send,
V: Send,
impl<K, V> Sync for TableTransaction<K, V> where
K: Sync,
V: Sync,
impl<K, V> Unpin for TableTransaction<K, V>
impl<K, V> UnwindSafe for TableTransaction<K, V> where
K: RefUnwindSafe,
V: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> FutureExt for T
impl<T> FutureExt for T
sourcefn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
sourcefn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
sourcefn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message T
in a tonic::Request
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more