Support retryable writes outside transactions
还没有人认领这个 Issue。
评估
调研方向
Start by reading Client::query() and the session state where retryableWriteNumber is tracked, then compare the existing transaction path with the MongoDB retryable writes specification. Define the eligible single-document commands, implicit session and transaction-number handling, and retryable errors before implementing the separate path. Done means specification tests cover safe retries while multi-document writes and unsupported commands remain excluded.
由索引模型根据 Issue 内容生成。
描述
Problem
The library supports sessions and transactions, but it does not implement MongoDB retryable writes for CRUD operations outside a transaction.
Client::query() adds txnNumber only when the session is in a transaction. retryableWriteNumber is tracked in the session state, but it is not used to build or retry a write command. As a result, insert, update, and delete issue a single command and applications cannot safely enable retryWrites=true.
Retrying an ambiguous network or primary step-down failure in application code can duplicate a write that MongoDB already applied.
Expected behavior
When retryable writes are enabled, the client should:
- create and manage an implicit server session for each eligible write;
- attach
lsidand a monotonically increasingtxnNumberto the command; - retry eligible single-document writes once for retryable network and server errors, using the same session and transaction number;
- preserve the at-most-once semantics provided by MongoDB;
- keep multi-document writes and unsupported commands out of the retry path;
- cover the behavior with the MongoDB retryable writes specification tests.
The existing session and transaction support looks like a good foundation, but retryable writes need a separate path from multi-document transactions.
Related observations from our integration
We are evaluating Utopia Mongo in a PHP/Hyperf service and built a provider adapter beside FastMongo, which uses the MongoDB Go driver. The following points are related to production use, but they are not prerequisites for this issue. Maintainers may prefer to track them separately.
Connection strings and topology discovery
Client is configured with one resolved host and port. To use a standard mongodb+srv URI, our adapter had to resolve SRV and TXT records, apply the TLS default, validate the SRV domain, discover a writable primary with hello, cache the result, and invalidate it after a connection or primary-change failure.
First-class support for MongoDB connection strings, including mongodb+srv, seed lists, relevant URI options, and topology refresh, would remove this application-specific infrastructure. FastMongo gets this behavior from the Go driver when it receives the URI.
Connection pool lifecycle
One Utopia Client owns one socket. In a coroutine application we needed a bounded pool with checkout timeout, disposal of failed clients, and invalidation when the resolved topology changed. A reusable pool utility, or documented guidance for this pattern, would make the library easier to adopt in long-running services.
This does not need to be a hidden global pool. An explicit pool with clear ownership would fit the current API well.
Scope and priority
We do not expect all of these capabilities to land together. Retryable writes are the immediate compatibility gap because a manual retry cannot reproduce their safety guarantees. The connection-string and pool observations are shared as integration feedback in case they help shape future work.
Context
MongoDB specification: https://specifications.readthedocs.io/en/latest/retryable-writes/retryable-writes/
FastMongo reference: https://github.com/Reasno/fastmongo
- 主要语言
- PHP
- 星标
- 6
- 派生
- 4
- 平均合并
- 12 分钟
- 30 天内合并 PR
- 1
环境准备
我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
utopia-php/mongo 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 48/100
utopia-php/mongo#39 ·
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
521xueweihan/HelloGitHub#3790 ·
-
bug
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 68/100
-
难度 2/5 1-3 小时 新手友好度 78/100
benjaminkott/bootstrap_package#1670 ·
-
sync-en
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 2 天内回复