mongodb data_error ai_generated true

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

ID: mongodb/capped-collection-invalid-oplog

Also available as: JSON · Markdown · 中文
85%Fix Rate
82%Confidence
1Evidence
2024-01-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
MongoDB 5.0 active
MongoDB 6.0 active
MongoDB 7.0 active

Root Cause

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

generic

中文

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

Official Documentation

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

Workarounds

  1. 80% success Restart the MongoDB instance with --repair to reconstruct the oplog: mongod --repair --dbpath /var/lib/mongodb
    Restart the MongoDB instance with --repair to reconstruct the oplog: mongod --repair --dbpath /var/lib/mongodb
  2. 95% success 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
    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. 85% success 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
    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. 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

Dead Ends

Common approaches that don't work:

  1. 90% fail

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

  2. 80% fail

    repairDatabase is not designed for internal system collections like oplog.

  3. 70% fail

    The corrupted entry remains in the oplog file after restart.