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
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 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.
官方文档
https://www.mongodb.com/docs/manual/core/sharding-balancer-administration/#chunk-migration-failures解决方案
-
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. -
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). -
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.
无效尝试
常见但无效的做法:
-
90% 失败
Pending deletions are internal metadata (range deletion tasks), not user documents; manual deletes do not affect them and may corrupt shard metadata.
-
85% 失败
Restarting clears in-memory state but the pending deletion tasks are persisted in config server metadata; they will resume after restart.
-
80% 失败
Splitting a range with pending deletions can cause orphaned documents and inconsistent metadata; the operation is rejected by the balancer.