mongodb data_error ai_generated true

MongoServerError: CappedCollection: 无效的 oplog 条目,时间戳为 { ts: Timestamp(0, 0) }

MongoServerError: CappedCollection: invalid oplog entry with timestamp { ts: Timestamp(0, 0) }

ID: mongodb/capped-collection-invalid-oplog

其他格式: JSON · Markdown 中文 · English
85%修复率
82%置信度
1证据数
2024-01-20首次发现

版本兼容性

版本状态引入弃用备注
MongoDB 5.0 active
MongoDB 6.0 active
MongoDB 7.0 active

根因分析

oplog 包含一个时间戳为零的损坏条目,可能是由于磁盘写入错误或不当关机导致。

English

The oplog contains a corrupted entry with a zero timestamp, likely due to a disk write error or improper shutdown.

generic

官方文档

https://www.mongodb.com/docs/manual/core/capped-collections/

解决方案

  1. Restart the MongoDB instance with --repair to reconstruct the oplog: mongod --repair --dbpath /var/lib/mongodb
  2. If the node is a secondary, resync from the primary by deleting the local database files and restarting: rm -rf /var/lib/mongodb/local/* && systemctl restart mongod
  3. Use mongodump with --oplog to export the oplog, then drop and re-import to clean corrupted entries: mongodump --db local --collection oplog.rs --out /tmp/oplog_backup; mongo local --eval 'db.oplog.rs.drop()'; mongorestore --db local --collection oplog.rs /tmp/oplog_backup/local/oplog.rs.bson

无效尝试

常见但无效的做法:

  1. 90% 失败

    The oplog is a special collection; manual deletion corrupts the storage engine state.

  2. 80% 失败

    repairDatabase is not designed for internal system collections like oplog.

  3. 70% 失败

    The corrupted entry remains in the oplog file after restart.