mongodb runtime_error ai_generated partial

MongoServerError:分片键范围删除冲突:分片'shard01'上的范围[minKey, maxKey)有待处理的删除操作

MongoServerError: Shard key range deletion conflict: range [minKey, maxKey) on shard 'shard01' has pending deletions

ID: mongodb/shard-key-range-deletion-conflict

其他格式: JSON · Markdown 中文 · English
80%修复率
84%置信度
1证据数
2024-06-18首次发现

版本兼容性

版本状态引入弃用备注
mongodb 6.0 active
mongodb 7.0 active
mongodb 8.0 active

根因分析

由于目标范围存在先前迁移的待处理删除任务,导致块迁移或删除命令失败,引发锁冲突。

English

A chunk migration or drop command failed because the target range has pending deletion tasks from a previous migration, causing a lock conflict.

generic

官方文档

https://www.mongodb.com/docs/manual/core/sharding-balancer-administration/#chunk-migration-failures

解决方案

  1. Wait for pending deletions to complete by monitoring the `config.chunks` collection: `db.getSiblingDB('config').chunks.find({ shard: 'shard01', lastmodEpoch: ... })` and check for `pending` flags; retry after 60 seconds.
  2. Manually clear pending range deletions using the internal command: `db.adminCommand({ _configsvrCommitRangeDeletion: 'config.system.chunks', range: { min: minKey, max: maxKey }, shard: 'shard01' })` (requires admin privileges and caution).
  3. Disable the balancer temporarily: `sh.stopBalancer(60000)` and then manually force a cleanup with `db.adminCommand({ cleanupOrphaned: 'mydb.mycoll', startingFromKey: minKey })` on the affected shard.

无效尝试

常见但无效的做法:

  1. 90% 失败

    Pending deletions are internal metadata (range deletion tasks), not user documents; manual deletes do not affect them and may corrupt shard metadata.

  2. 85% 失败

    Restarting clears in-memory state but the pending deletion tasks are persisted in config server metadata; they will resume after restart.

  3. 80% 失败

    Splitting a range with pending deletions can cause orphaned documents and inconsistent metadata; the operation is rejected by the balancer.