feat(mongodb): make transaction read concern configurable - #314
Open
xgerman wants to merge 4 commits into
Open
Conversation
The MongoDB storage backend hardcodes readConcern: snapshot on every multi-document transaction (conditional writes, TransactWriteItems, TransactGetItems, idempotency tokens). Real MongoDB (7.0+) supports this, but some MongoDB-wire-compatible servers do not. Concretely, DocumentDB (github.com/documentdb/documentdb) rejects transactions started with readConcern: snapshot with 'Error code 115 (CommandNotSupported)', which made the mongodb backend unusable against it beyond CreateTable. Add storage.mongodb.transaction_read_concern (default: "snapshot", preserving current behavior) so operators can set "majority" or "local" to run against backends that don't implement snapshot reads, trading off snapshot isolation for compatibility. Validated end-to-end against DocumentDB 0.116.0 (PutItem/GetItem/CreateTable/DeleteTable all succeed with transaction_read_concern = "majority"). Also widens the StorageConfig trait-object bound used by ServerComponentsFactory from an elided reference lifetime to 'static, since StorageConfig::as_any()'s downcast (already documented as intended for backend-specific settings like this one) requires it -- without it, Any::downcast_ref cannot be proven sound against an unannotated &dyn StorageConfig. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1de8a53e-4145-4deb-8d82-294a4879046e Signed-off-by: German <geeichbe@microsoft.com>
Updates the MongoDB backend design doc (13-storage-mongodb.md) to reflect that transaction read concern is now configurable via storage.mongodb.transaction_read_concern, rather than unconditionally snapshot. Left the RFC (docs/rfcs/0000-mongodb-backend.md) as a point-in-time design record, matching this repo's convention for RFCs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1de8a53e-4145-4deb-8d82-294a4879046e Signed-off-by: German <geeichbe@microsoft.com>
xgerman
requested review from
LeeroyHannigan,
amrith,
c33howard,
jcshepherd,
pdf-amzn,
robinnsc and
yesyayen
as code owners
August 26, 2026 04:10
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.
Problem
The MongoDB storage backend hardcodes
readConcern: snapshoton every multi-document transaction it opens (conditional writes,TransactWriteItems,TransactGetItems, idempotency-token checks). Real MongoDB (7.0+) supports this and it's the strongest available isolation level, but some MongoDB-wire-compatible servers do not implement it.Concretely, DocumentDB (a Postgres-based MongoDB-API-compatible database) rejects transactions started with
readConcern: snapshotwithError code 115 (CommandNotSupported), which makes the mongodb backend unusable against it beyondCreateTable.Change
Adds
storage.mongodb.transaction_read_concern(default:"snapshot", preserving current behavior) so operators can set"majority"or"local"to run against backends that don't implement snapshot reads, trading off snapshot isolation for compatibility. Also updates the MongoDB backend design doc (docs/design/13-storage-mongodb.md) to describe the new setting.As a side effect, this widens
ServerComponentsFactory'sStorageConfigtrait-object bound from an elided reference lifetime to'static.StorageConfig::as_any()'s downcast is already documented as the intended mechanism for backend-specific settings like this one, butAny::downcast_refrequires the pointee to be provably'static— an unannotated&dyn StorageConfigdoesn't satisfy that, so the downcast wouldn't compile without this change. All existing callers already own'staticdata (Box<dyn StorageConfig>), so this is not a breaking change for callers.Validation
cargo build --workspace,cargo test(all touched crates pass),cargo clippy --workspace -- -D warningsclean.transaction_read_concern = "majority":CreateTable,PutItem,GetItem, andDeleteTableall succeeded via the DynamoDB API surface.transaction_read_concernunset) is unchanged — stillsnapshot.Trade-offs
Running with
majority/localinstead ofsnapshotweakens isolation between concurrent transactions on backends that use this setting — concurrent transactions may observe a less consistent view of the data than under true snapshot reads. This is called out in both the sample config and the design doc.