moiradb::moira

Struct Task

source
pub struct Task<K, V, C>
where C: Debug + ?Sized, K: Debug, V: Debug,
{ pub seq: u64, pub kv_store: HashMap<K, WriteType<V>>, pub write_set: HashSet<K>, pub outcome: TransactionResult, pub transaction: Arc<Transaction<K, C>>, /* private fields */ }
Expand description

There is 1 moira::Task per transaction.

Fields§

§seq: u64§kv_store: HashMap<K, WriteType<V>>

A local cache of key/values, read/write

§write_set: HashSet<K>

The keys we expect the transaction to write to

§outcome: TransactionResult

The outcome of executing the command

§transaction: Arc<Transaction<K, C>>

A reference to the transaction to execute

Implementations§

source§

impl<K, V, C> Task<K, V, C>
where K: 'static + Send + Serialize + Eq + Hash + Clone + Debug, V: 'static + Send + Sync + Serialize + DeserializeOwned + Debug, C: Command<K, V> + Debug,

source

pub fn new( transaction: Arc<Transaction<K, C>>, read_commands: UnboundedSender<MoiraCommand<K, V, C>>, ) -> Task<K, V, C>

Construct a new instance of MoiraTask.

source

pub async fn read(&mut self, key: K) -> DBValue<V>

Read data from the local cache or, in a case where the data is not cached locally, from the MultiVersionedStore.

source

pub async fn write(&mut self, key: K, value: DBValue<V>)

Inserts the key and the value into the local key-value cache

source

pub async fn delete(&mut self, key: K)

Inserts a None value for a given key, effectively deleting any stored data.

source

pub async fn set_outcome(self, state: TransactionResult)

Sends back results to MoiraTask to commit, or abort or reschedule db writes to the backing store. Consumes this instance of MoiraTask.

When a command executes, it returns Abort, Commit, or Reschedule.

Abort stops execution.

Commit, and this transaction has only written to the originally expected values in the write set, we can commit.

But if it has written to more keys than what was originally expected, we need to reschedule it for a later commit version. Later, we will re-run the deferred future(s) and include the proper set of keys, so that the future result will be consistent.

source

pub async fn run_command(self) -> u64

Run the command, then consume this MoiraTask in set_outcome()

source§

impl<K, V, C> Task<K, V, C>
where K: 'static + Send + Serialize + Eq + Hash + Clone + Debug, V: 'static + Send + Sync + Serialize + DeserializeOwned + Debug, C: Debug + MergeCommand<K, V>,

source

pub async fn merge(&mut self, key: K, value: DBValue<V>)

source

pub async fn collect(&mut self, key: K) -> DBValue<V>

Trait Implementations§

source§

impl<K, V, C> Debug for Task<K, V, C>
where C: Debug + Debug + ?Sized, K: Debug + Debug, V: Debug + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K, V, C> Freeze for Task<K, V, C>
where C: ?Sized,

§

impl<K, V, C> RefUnwindSafe for Task<K, V, C>

§

impl<K, V, C> Send for Task<K, V, C>
where C: Sync + Send + ?Sized, K: Send + Sync, V: Sync + Send,

§

impl<K, V, C> Sync for Task<K, V, C>
where C: Sync + Send + ?Sized, K: Sync + Send, V: Sync + Send,

§

impl<K, V, C> Unpin for Task<K, V, C>
where K: Unpin, C: ?Sized,

§

impl<K, V, C> UnwindSafe for Task<K, V, C>

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