pub struct Task<K, V, C>{
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: TransactionResultThe 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>
impl<K, V, C> Task<K, V, C>
sourcepub fn new(
transaction: Arc<Transaction<K, C>>,
read_commands: UnboundedSender<MoiraCommand<K, V, C>>,
) -> Task<K, V, C>
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.
sourcepub async fn read(&mut self, key: K) -> DBValue<V>
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.
sourcepub async fn write(&mut self, key: K, value: DBValue<V>)
pub async fn write(&mut self, key: K, value: DBValue<V>)
Inserts the key and the value into the local key-value cache
sourcepub async fn delete(&mut self, key: K)
pub async fn delete(&mut self, key: K)
Inserts a None value for a given key, effectively deleting any stored data.
sourcepub async fn set_outcome(self, state: TransactionResult)
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.
sourcepub async fn run_command(self) -> u64
pub async fn run_command(self) -> u64
Run the command, then consume this MoiraTask in set_outcome()