mongodb
runtime_error
ai_generated
true
MongoServerError:事务对于快照来说太旧:读取时间戳早于存储引擎中最旧的时间戳
MongoServerError: TransactionTooOldForSnapshot: Read timestamp is older than the oldest timestamp in the storage engine
ID: mongodb/transaction-snapshot-too-old
85%修复率
85%置信度
1证据数
2024-06-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| mongodb-4.0 | active | — | — | — |
| mongodb-4.2 | active | — | — | — |
| mongodb-4.4 | active | — | — | — |
| mongodb-5.0 | active | — | — | — |
| mongodb-6.0 | active | — | — | — |
| mongodb-7.0 | active | — | — | — |
根因分析
多文档事务尝试读取已被存储引擎由于缓存压力或写入冲突修剪的快照。
English
A multi-document transaction attempted to read from a snapshot that has been pruned by the storage engine due to cache pressure or write conflicts.
官方文档
https://www.mongodb.com/docs/manual/core/transactions/解决方案
-
Reduce transaction duration by committing quickly. Keep transactions as short as possible; avoid long-running transactions with many operations. Example: session.startTransaction(); await collection1.insertOne(a); await collection2.updateOne(b); await session.commitTransaction();
-
Increase the WiredTiger cache size to retain older snapshots: storage.wiredTiger.engineConfig.cacheSizeGB: 8. Restart mongod.
-
If the transaction conflicts with writes, use retry logic with exponential backoff. Example in Python: for i in range(3): try: with client.start_session() as session: session.start_transaction(); ...; session.commit_transaction(); break except pymongo.errors.OperationFailure as e: if 'TransactionTooOldForSnapshot' in str(e): time.sleep(0.5 * (2**i)); continue
无效尝试
常见但无效的做法:
-
80% 失败
This does not affect snapshot pruning; the error is about the read timestamp being too old, not the transaction timing out.
-
70% 失败
Snapshot read concern is already the default for transactions; the issue is the snapshot itself being pruned.
-
100% 失败
This is not configurable and would cause memory exhaustion.