mongodb data_error ai_generated partial

MongoServerError: orphan documents detected during chunk migration on namespace mydb.mycoll

ID: mongodb/sharded-cluster-orphan-documents

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
MongoDB 6.0 active
MongoDB 7.0 active
MongoDB 8.0 active

Root Cause

Chunk migration left behind documents that do not belong to the new shard range due to concurrent writes or a failed migration cleanup.

generic

中文

由于并发写入或迁移清理失败,块迁移留下了不属于新分片范围的文档。

Workarounds

  1. 80% success Use the cleanupOrphaned command on the affected shard to remove orphan documents: db.adminCommand({ cleanupOrphaned: 'mydb.mycoll' }).
    Use the cleanupOrphaned command on the affected shard to remove orphan documents: db.adminCommand({ cleanupOrphaned: 'mydb.mycoll' }).
  2. 85% success Temporarily disable the balancer (sh.stopBalancer()) and manually re-migrate the chunk to ensure consistent range coverage.
    Temporarily disable the balancer (sh.stopBalancer()) and manually re-migrate the chunk to ensure consistent range coverage.
  3. 70% success Verify shard key distribution and adjust chunk boundaries using splitChunk to isolate orphan documents.
    Verify shard key distribution and adjust chunk boundaries using splitChunk to isolate orphan documents.

中文步骤

  1. Use the cleanupOrphaned command on the affected shard to remove orphan documents: db.adminCommand({ cleanupOrphaned: 'mydb.mycoll' }).
  2. Temporarily disable the balancer (sh.stopBalancer()) and manually re-migrate the chunk to ensure consistent range coverage.
  3. Verify shard key distribution and adjust chunk boundaries using splitChunk to isolate orphan documents.

Dead Ends

Common approaches that don't work:

  1. 80% fail

    Deletion without verifying shard key ranges can cause data loss.

  2. 90% fail

    Orphans persist after restart unless the balancer re-migrates or cleanup runs.

  3. 50% fail

    Cleanup may conflict with ongoing balancer operations, requiring repeated runs.