mongodb
system_error
ai_generated
true
MongoServerError:OplogTruncation:由于缺少 oplog 条目,复制恢复失败
MongoServerError: OplogTruncation: replication recovery failed due to missing oplog entries
ID: mongodb/oplog-truncation-during-recovery
85%修复率
87%置信度
1证据数
2023-11-20首次发现
根因分析
由于复制延迟或手动删除,oplog 在辅助节点重放所有条目之前被截断,导致复制流中出现无法恢复的间隙。
English
The oplog was truncated (e.g., due to replication lag or manual deletion) before a secondary could replay all entries, causing an irrecoverable gap in the replication stream.
官方文档
https://www.mongodb.com/docs/manual/tutorial/resync-replica-set-member/解决方案
-
Resync the secondary from scratch: stop the secondary, delete its data directory (e.g., rm -rf /data/db/*), then restart and let it perform an initial sync from the primary.
-
If the primary still has the missing oplog entries (e.g., in a backup), restore them manually using mongorestore with --oplogReplay, then restart replication.
无效尝试
常见但无效的做法:
-
95% 失败
Increasing oplog size (e.g., via --oplogSizeMB) prevents future truncation but does not recover the lost entries; the secondary remains stuck.
-
90% 失败
Restarting the secondary node only re-attempts the same recovery, which fails again since the oplog gap persists.