The ARX specification
05 Transactions and batch scopes
Connections and transactions
Application code opens transactions with ARX's own types, never the driver's: a provider connection
(new ArxPgConnection(cs), ArxMsSqlConnection, ArxMySqlConnection, ArxMongoConnection, ArxDynamoConnection),
BeginTransactionAsync(), an ArxTransaction passed to each call, then CommitAsync().
- Disposing a transaction that wasn't committed rolls it back. Nothing is ever committed on dispose.
- A commit the database refuses (a deferred constraint, a serialization failure) leaves the transaction rolled back. A
commit whose answer never comes (the connection fails or times out after it was sent) leaves its outcome unknown:
the state says so (
OutcomeUnknown), and the error is not transient, so a retry policy doesn't run the work again unchecked. The same holds for a batch scope's commit. - A database failure inside a transaction aborts it (
IsAborted): every later call andCommitAsyncis ARX1015 TransactionAborted. A committed, rolled back or disposed transaction is ARX1010 TransactionCompleted; one of another connection is ARX1009 TransactionMismatch. - A provider whose database doesn't run several calls in one transaction may collect the writes and send them together at the commit (DynamoDB), and must then say that a failure shows at the commit and that reads don't see the pending writes.
Batch scopes
A batch scope is one transaction across many calls, with the operations of chapter 03 on the scope itself.
| Opened with | Commit |
|---|---|
BeginBatchAsync(options) |
manual: CommitAsync(); disposing without it rolls back |
RunBatchAsync(body, options) |
automatic: committed when the body returns, rolled back if it throws (the exception is rethrown unchanged) |
- Savepoints (off by default, from 0.1.0-preview.5): without them a failed call rolls the whole scope back, on every
provider, and a later call is ARX1015. Asked for (
Savepoints = true), each call runs under a savepoint, so a failed call is undone alone and the scope goes on. A provider whose database has none (MongoDB, DynamoDB) refusestruewith ARX8001. - One call at a time: a call while another of the same scope runs is ARX1014 BatchScopeBusy.
- The scope reports its state (Active, Committed, RolledBack, Failed), how many calls it ran, the rows written and the calls that failed.