DistributedWriteTransaction SHALL support Create, Replace, Delete, Upsert, and Patch operations. Each operation SHALL independently specify its target database, container, partition key, and document id, allowing operations to target any combination of partitions and containers within the same database account.
- WHEN a
DistributedWriteTransactionis built with operations targeting different partition keys within the same container - THEN
CommitTransactionAsyncSHALL commit all operations atomically
- WHEN a
DistributedWriteTransactionis built with operations targeting different containers within the same database account - THEN
CommitTransactionAsyncSHALL commit all operations atomically
After a successful commit, the response SHALL expose an ETag for each write operation, reflecting the server-assigned version of the written document.
- WHEN
CommitTransactionAsynccompletes withIsSuccessStatusCode = true - THEN each operation's result SHALL carry a non-null
ETagthat can be used asIfMatchEtagon a subsequentDistributedWriteTransactionfor optimistic concurrency
Each operation in a DistributedWriteTransaction SHALL support an IfMatchEtag precondition. If the document's current ETag does not match, the entire transaction SHALL be rolled back.
- WHEN
CommitTransactionAsyncis called and one operation'sIfMatchEtagdoes not match the document's current ETag - THEN the service SHALL roll back all operations and the failed operation's result SHALL carry
StatusCode = 412 Precondition Failed - AND all other operations SHALL carry
StatusCode = 424 Failed Dependency
DistributedWriteTransaction SHALL atomically commit all staged write operations across any partitions and containers within the same database account. If any operation fails, the service SHALL roll back all operations in the transaction.
- WHEN
CommitTransactionAsyncis called and all operations are valid and commit successfully - THEN the SDK SHALL return a
DistributedTransactionResponsewithIsSuccessStatusCode = trueandStatusCode = 200
- WHEN
CommitTransactionAsyncis called and at least one operation fails (e.g., ETag mismatch, conflict) - THEN the service SHALL roll back all operations and the SDK SHALL return a
DistributedTransactionResponsewithIsSuccessStatusCode = false - AND the failed operation's result SHALL carry the specific failure status code (e.g., 412 Precondition Failed, 409 Conflict)
- AND all other operations SHALL carry
StatusCode = 424 Failed Dependency
After a commit completes (success or failure), the SDK SHALL merge per-operation session tokens from the response into the client's ISessionContainer.
- WHEN
CommitTransactionAsynccompletes and the response contains per-operationsessionTokenvalues - THEN the SDK SHALL call
ISessionContainer.SetSessionTokenfor each operation's response token so that subsequent reads on any affected partition observe the committed writes
Each CommitTransactionAsync call SHALL auto-generate a unique idempotency token and send it as x-ms-idempotency-token. The token SHALL be exposed on the response so callers can safely replay a commit whose outcome is unknown.
- WHEN a caller retries
CommitTransactionAsyncusing theIdempotencyTokenfrom a previous response - THEN the service SHALL return the same result as the original commit without applying the operations a second time
The SDK SHALL route every CommitTransactionAsync request through the Gateway or Thin Client endpoint. Direct mode is not supported for distributed transactions.
- WHEN the
CosmosClientis configured with Direct connectivity mode - THEN the SDK SHALL override connectivity to Gateway mode and route
CommitTransactionAsyncto the Gateway write-transaction endpoint
CommitTransactionAsync SHALL throw NotSupportedException if the account is configured with multiple write regions.
- WHEN the Cosmos DB account has
UseMultipleWriteLocations = true - THEN
CommitTransactionAsyncSHALL throwNotSupportedExceptionbefore sending any request
The SDK SHALL reject a CommitTransactionAsync call before dispatch if the staged operations exceed the supported limits.
- WHEN more than 100 operations have been staged on the transaction
- THEN
CommitTransactionAsyncSHALL throwArgumentExceptionbefore sending any request
- WHEN the total serialized request body would exceed 2 MB
- THEN
CommitTransactionAsyncSHALL throwArgumentExceptionbefore sending any request
When the Gateway returns 429 (Too Many Requests), the SDK SHALL automatically retry after the x-ms-retry-after-ms interval, up to the configured maximum retry count.
- WHEN
CommitTransactionAsyncreceives a 429 response - THEN the SDK SHALL wait for
x-ms-retry-after-msand retry the commit with the same idempotency token
The SDK SHALL emit an OpenTelemetry span for each CommitTransactionAsync call.
- WHEN
CommitTransactionAsynccompletes successfully - THEN the SDK SHALL emit a span with
db.cosmosdb.operation_type = "CommitDistributedTransaction",db.cosmosdb.status_code = 200, anddb.cosmosdb.request_chargeset to the total RU charge for the transaction