DTX for Rust - #4702
Merged
Merged
Conversation
…to users/fabianm/dtx
…to users/fabianm/QueryInMemEmulator
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
When a container or database is deleted in the in-memory emulator, the associated offer entries in each region's `offers` map are now also removed. Previously, `cascade_delete_container` and `cascade_delete_database` left these entries behind, causing `ReadFeedOffers` and `QueryOffers` to return stale orphaned offers after deletion. Co-authored-by: FabianMeiswinkel <19165014+FabianMeiswinkel@users.noreply.github.com>
A real Cosmos DB account returns 207 Multi-Status when any individual operation in a transactional batch fails, and 200 OK only when all operations succeed. Update the in-memory emulator to match this behavior by checking whether any result has a statusCode >= 300 and selecting the appropriate overall response status. Update the corresponding test to expect 207 on partial failure. Co-authored-by: FabianMeiswinkel <19165014+FabianMeiswinkel@users.noreply.github.com>
…/Azure/azure-sdk-for-rust into users/fabianm/dtx
…to users/fabianm/dtx
Fabian Meiswinkel (FabianMeiswinkel)
requested a review
from a team
as a code owner
July 7, 2026 00:43
Copilot started reviewing on behalf of
Fabian Meiswinkel (FabianMeiswinkel)
July 7, 2026 00:43
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a preview (“disabled by default”) Distributed Transactions (DTX) capability to the Cosmos Rust driver (azure_data_cosmos_driver) and exposes a corresponding gated builder-based API in the public SDK (azure_data_cosmos), plus emulator support, tests, and a design/spec document.
Changes:
- Introduces
preview_dtx-gated driver wire models, request/response handling, retries, and session-token behavior forPOST /operations/dtc. - Adds
preview_dtx-gated SDK transaction builders and response accessors, and updates the in-memory emulator to handle/operations/dtc. - Adds integration tests (emulator + optional live comparison), documentation/spec, changelog entries, and cSpell terms.
Show a summary per file
| File | Description |
|---|---|
| sdk/cosmos/azure_data_cosmos/tests/in_memory_emulator_tests/mod.rs | Gates new DTX live-comparison test module behind preview_dtx. |
| sdk/cosmos/azure_data_cosmos/tests/in_memory_emulator_tests/dtx_live_comparison.rs | Adds dual-backend emulator vs live DTX parity test (ignored by default). |
| sdk/cosmos/azure_data_cosmos/src/clients/mod.rs | Re-exports DTX SDK types and wires new module behind preview_dtx. |
| sdk/cosmos/azure_data_cosmos/src/clients/distributed_transaction.rs | Adds preview SDK DTX builders and response accessors. |
| sdk/cosmos/azure_data_cosmos/src/clients/cosmos_client.rs | Adds preview factory methods for distributed read/write transactions. |
| sdk/cosmos/azure_data_cosmos/src/clients/container_client.rs | Exposes resolved ContainerReference under preview_dtx. |
| sdk/cosmos/azure_data_cosmos/CHANGELOG.md | Documents the new preview DTX SDK surface. |
| sdk/cosmos/azure_data_cosmos/Cargo.toml | Adds uuid dependency + preview_dtx feature wiring to driver. |
| sdk/cosmos/azure_data_cosmos_driver/tests/in_memory_emulator_tests/mod.rs | Adds DTX emulator test module behind preview_dtx. |
| sdk/cosmos/azure_data_cosmos_driver/tests/in_memory_emulator_tests/distributed_transaction.rs | Adds emulator integration tests for /operations/dtc. |
| sdk/cosmos/azure_data_cosmos_driver/src/models/vector_session_token.rs | Updates vector session token parsing/merging to support -1 sentinel. |
| sdk/cosmos/azure_data_cosmos_driver/src/models/mod.rs | Exposes DTX models + adds new ResourceType/OperationType variants behind feature. |
| sdk/cosmos/azure_data_cosmos_driver/src/models/distributed_transaction.rs | Adds DTX wire models, serialization, parsing, status promotion, and unit tests. |
| sdk/cosmos/azure_data_cosmos_driver/src/models/cosmos_resource_reference.rs | Adds resource-path/signing handling for DTX coordinator endpoint. |
| sdk/cosmos/azure_data_cosmos_driver/src/models/cosmos_operation.rs | Adds CosmosOperation::distributed_transaction and idempotency/read-only tests. |
| sdk/cosmos/azure_data_cosmos_driver/src/in_memory_emulator/store.rs | Adds counter rollback helper for DTX abort semantics. |
| sdk/cosmos/azure_data_cosmos_driver/src/in_memory_emulator/operations.rs | Adds /operations/dtc handler implementing DTX read/write semantics. |
| sdk/cosmos/azure_data_cosmos_driver/src/in_memory_emulator/dispatch.rs | Routes POST /operations/dtc and parses it into an emulator operation. |
| sdk/cosmos/azure_data_cosmos_driver/src/error/cosmos_status.rs | Adds DTX-related substatus codes behind preview_dtx. |
| sdk/cosmos/azure_data_cosmos_driver/src/driver/transport/transport_pipeline.rs | Adjusts 429 retry eligibility for body-bearing DTX responses; adds DTX detection. |
| sdk/cosmos/azure_data_cosmos_driver/src/driver/transport/mod.rs | Marks DTX resource type as dataplane for pipeline selection. |
| sdk/cosmos/azure_data_cosmos_driver/src/driver/routing/session_manager.rs | Adds DTX session-token resolve/merge logic behind preview_dtx. |
| sdk/cosmos/azure_data_cosmos_driver/src/driver/routing/session_container.rs | Adds strict session-token merge helper behind preview_dtx. |
| sdk/cosmos/azure_data_cosmos_driver/src/driver/pipeline/retry_evaluation.rs | Adds DTX-specific retry classification for bodyless coordinator/infra failures. |
| sdk/cosmos/azure_data_cosmos_driver/src/driver/pipeline/operation_pipeline.rs | Adds handling for new OperationAction::DtxRetry. |
| sdk/cosmos/azure_data_cosmos_driver/src/driver/pipeline/components.rs | Adds DTX retry counters/budgets and new pipeline action behind feature. |
| sdk/cosmos/azure_data_cosmos_driver/src/driver/cosmos_driver.rs | Adds execute_distributed_transaction outer retry loop and request header stamping. |
| sdk/cosmos/azure_data_cosmos_driver/docs/DISTRIBUTED_TRANSACTIONS_SPEC.md | Adds a detailed DTX design/spec/ADR document. |
| sdk/cosmos/azure_data_cosmos_driver/CHANGELOG.md | Documents new preview DTX driver functionality. |
| sdk/cosmos/azure_data_cosmos_driver/Cargo.toml | Adds preview_dtx feature flag. |
| sdk/cosmos/.cspell.json | Adds DTX-related terms to cSpell dictionary. |
Review details
- Files reviewed: 31/31 changed files
- Comments generated: 2
- Review effort level: Low
Abhijeet Mohanty (jeet1995)
approved these changes
Jul 7, 2026
Member
Author
|
/azp run rust - cosmos - weekly |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Ashley Stanton-Nurse (analogrelay)
approved these changes
Jul 7, 2026
Ashley Stanton-Nurse (analogrelay)
left a comment
Member
There was a problem hiding this comment.
My only naming nit is in an internal API, so it's non-blocking.
Member
Author
|
/azp run rust - cosmos - weekly |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Meghana Palaparthi (Meghana-Palaparthi)
approved these changes
Jul 7, 2026
Member
Author
|
/azp run rust - cosmos - weekly |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Abhijeet Mohanty (jeet1995)
approved these changes
Jul 7, 2026
Ashley Stanton-Nurse (analogrelay)
approved these changes
Jul 7, 2026
Member
Author
|
Test failure in weekly is unrelated |
Fabian Meiswinkel (FabianMeiswinkel)
merged commit Jul 7, 2026
1eb9f45
into
main
33 of 35 checks passed
yumnahussain
added a commit
that referenced
this pull request
Jul 8, 2026
Merges origin/main (which landed #4702, preview distributed transactions) into the AVAD change-feed branch. The DTX PR added the in-memory emulator's DTX operation paths, which construct ParsedRequest without the change-feed a_im field this branch adds. Under --all-features (which enables preview_dtx) those two initializers failed to compile with E0063. Set a_im: None on both DTX-derived ParsedRequest values (DTX operations carry no A-IM header), fixing the --all-features build/clippy/api-report CI jobs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds preview Distributed Transactions (DTX) support to the Rust Cosmos driver and SDK.
Distributed Transactions extend Cosmos DB atomicity beyond
TransactionalBatch's single-container / single-partition-key boundary. With this change, Rust clients can prepare and execute multi-partition, multi-container transactions within a single Cosmos DB account through the service-side Distributed Transactions Coordinator (DTC).The implementation is intentionally gated behind a disabled-by-default
preview_dtxfeature because the DTX service feature is still in preview/test-account rollout and is not production-ready.Important References
sdk/cosmos/azure_data_cosmos_driver/docs/DISTRIBUTED_TRANSACTIONS_SPEC.mdWhat Changed
Driver (
azure_data_cosmos_driver)Adds preview DTX driver support behind
preview_dtx:DistributedTransactionTypeDistributedTransactionOperationKindDistributedTransactionTargetDistributedTransactionOperationDistributedTransactionRequestDistributedTransactionResponseDistributedTransactionOperationResultDistributedTransactionResultBodyPOST /operations/dtcx-ms-cosmos-idempotency-tokenx-ms-cosmos-operation-typex-ms-cosmos-resource-type: DistributedTransactionBatchoperations[]payloadindexisRetriableanddiagnosticString207 MultiStatusaccording to the DTX contractisRetriable429uses the shared throttle retry path; body-bearing DTX429is handled by the outer coordinator retry pathDTC_COORDINATOR_RACE_CONFLICTDTC_LEDGER_FAILUREDTC_ACCOUNT_CONFIG_FAILUREDTC_DISPATCH_FAILUREDTC_OPERATION_ROLLED_BACKSDK (
azure_data_cosmos)Adds preview public SDK transaction builders behind
preview_dtx.The SDK API now follows the same broad shape as
TransactionalBatch: callers prepare a data-only transaction document and pass it to the account client for execution.DistributedWriteTransaction::new()DistributedReadTransaction::new()CosmosClient::commit_distributed_write(...)CosmosClient::execute_distributed_read(...)&ContainerClient; the SDK resolves the underlying driverContainerReferenceinternally.CosmosClient.DistributedWriteTransactioncreate_itemreplace_itemupsert_itemdelete_itempatch_itemDistributedReadTransactionread_itemDistributedTransactionOperationOptionssession_tokenpreconditionDistributedTransactionPatchOperationOptionssession_tokenpreconditionfilter_predicateDistributedTransactionResponsestatusis_success_status_codeis_completed_status_codelenis_emptyoperation_resultheadersdiagnostic_stringidempotency_tokenis_retriableerror_messagediagnosticsactivity_idrequest_chargeretry_after_msDistributedTransactionOperationResultindexstatus_codesub_status_codeis_success_status_codeis_completed_status_codeetagsession_tokenpartition_key_range_idrequest_chargeresource<T>()DistributedWriteTransactionandDistributedReadTransactionare intentionally data-only builders. They do not carry a client and do not execute themselves. Execution happens throughCosmosClient::commit_distributed_write(...)orCosmosClient::execute_distributed_read(...), which consumes the prepared transaction and validates that every operation targets the same Cosmos DB account as the executing client.In-Memory Emulator Support
DTX is not available in the normal emulator or emulator vnext today, and live DTX testing requires special test accounts. To enable local iteration, this PR adds DTX support to the in-memory emulator:
POST /operations/dtc453 / 5415424 FailedDependency304 NotModifiedread transaction handlingPublic API Example