-
Notifications
You must be signed in to change notification settings - Fork 643
Open
Description
Define new host functions for acquiring, committing, aborting a transaction. Expose these to module bindings as the following interface:
impl ProcedureContext {
/// Acquire a mutable transaction and execute `body` with read-write access to the database.
///
/// If the `body` returns `Ok`, the transaction will be committed and its mutations persisted.
/// If the `body` returns `Err`, the transaction will be rolled back and its mutations discarded.
///
/// Regardless of the transaction's success or failure,
/// the return value of `body` is not persisted to the commitlog or broadcast to subscribed clients.
/// Clients attribute mutations performed by this transaction to `Event::UnknownTransaction`.
///
/// If the transaction fails to commit after `body` returns (e.g. due to a conflict with a concurrent transaction),
/// this method will re-invoke `body` with a new transaction in order to retry.
pub fn with_transaction<Res, Err>(&mut self, body: impl Fn(&TxContext) -> Result<Res, Err>)) -> Result<Res, Err> {
todo!()
}
}The TxContext is a lot like a ReducerContext: it has a db field which allows access to the database, offers the rng method, has a timestamp, and probably some other stuff I'm forgetting. It inherits auth information from the enclosing ProcedureContext.
Name the new host functions with the prefix procedure_.
Attempting to perform any of the other procedure_ host calls while a transaction is open should error.
After completing this, create follow-up tickets to implement the same in C#, C++ and TypeScript.
Metadata
Metadata
Assignees
Labels
No labels