Skip to content

Comments

Add ProcedureContext::with_tx#3638

Merged
Centril merged 15 commits intomasterfrom
centril/proc-with-transaction
Nov 19, 2025
Merged

Add ProcedureContext::with_tx#3638
Centril merged 15 commits intomasterfrom
centril/proc-with-transaction

Conversation

@Centril
Copy link
Contributor

@Centril Centril commented Nov 11, 2025

Description of Changes

Adds ProcedureContext::{with_tx, try_with_tx}.

Fixes #3515.

API and ABI breaking changes

None

Expected complexity level and risk

2

Testing

An integration test test_calling_with_tx is added.

@Centril Centril force-pushed the centril/proc-with-transaction branch 2 times, most recently from fcaf181 to ef30e09 Compare November 12, 2025 18:55
@Centril Centril changed the title Add ProcedureContext::with_transaction Add ProcedureContext::with_tx Nov 12, 2025
Copy link
Contributor

@gefjon gefjon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • See comment in ModuleSubscriptions::send_procedure_message: I think (but am not confident) that we need to pass the procedure's last-referenced TX offset through and delay the procedure message in the case where the client is subscribed to confirmed reads. If I'm wrong about that because the queue is ordered anyways, you should instead update the comment with my reasoning. But I don't think that's right - if the client is not subscribed to the TX's writes, or if the TX was aborted rather than committed, we still should delay the procedure result message. In the rolled-back TX case we should include the most recent committed TX at the time of the rollback, I think.
  • I would greatly appreciate a test case added to the sdk-test-procedure module and sdks/rust/tests/procedure-client which exercises this functionality, including observing rows inserted within the TX.

@bfops bfops added the release-any To be landed in any release window label Nov 17, 2025
@Centril Centril force-pushed the centril/proc-with-transaction branch 4 times, most recently from bef087f to 8da6dbe Compare November 19, 2025 01:15
Copy link
Contributor

@gefjon gefjon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks! Minor nits which I'll trust you to handle appropriately.

@Centril Centril force-pushed the centril/proc-with-transaction branch from 649057b to fedede8 Compare November 19, 2025 18:09
@Centril Centril enabled auto-merge November 19, 2025 18:10
@Centril Centril force-pushed the centril/proc-with-transaction branch from fedede8 to b769e58 Compare November 19, 2025 19:02
@Centril Centril added this pull request to the merge queue Nov 19, 2025
Merged via the queue into master with commit 0a32517 Nov 19, 2025
34 of 37 checks passed
github-merge-queue bot pushed a commit that referenced this pull request Dec 18, 2025
# Description of Changes

Implements the C# equivalent of #3638

This implement uses inheritance, where abstract base classes (like
`ProcedureContextBase` in `ProcedureContext.cs`) store the core of the
implementation, and then generated wrappers (like `ProcedureContext` in
the generated FFI.cs file) inherit from them.

For error handling, we work like Rust's implementation of `Result<T,E>`
but we require `where E : Exception` because of how exceptions work in
C#. Transaction-level failures come back as a `TxOutcome` and user
errors should follow the `Result<T,E>` pattern. In this implementation,
we have `UnwrapOrThrow()` throws exceptions directly because of C#'s
error handling pattern.

Unlike the Rust implementation's direct `Result` propagation, we are
using an `AbortGuard` pattern (in `ProcedureContext.cs`) for exception
handling, which uses `IDisposable` for automatic cleanup.

Most changes should have fairly similar Rust-equivalents beyond that.
For module authors, the changes here allow for the transation logic to
work like:
```csharp
ctx.TryWithTx<ResultType, Exception>(tx => {
    // transaction logic
    return Result<ResultType, Exception>.Ok(result);
});
```
This change includes a number of tests added to the
`sdks/csharp/examples~/regression-tests/`'s `server` and `client` to
validate the behavior of the changes. `server` changes provide further
usage examples for module authors.

# API and ABI breaking changes

Should not be a breaking change

# Expected complexity level and risk

2

# Testing

- [x] Created Regression Tests that show transitions in procedures
working in various ways, all of which pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-any To be landed in any release window

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Procedures: Add transaction API

4 participants