mongodb
runtime_error
ai_generated
partial
MongoServerError: Balancer round failed: chunk migration failed for namespace test.users, reason: cannot move chunk because the source shard has no primary
ID: mongodb/balancer-round-failed
82%Fix Rate
85%Confidence
1Evidence
2025-03-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| MongoDB 5.0 | active | — | — | — |
| MongoDB 6.0 | active | — | — | — |
| MongoDB 7.0 | active | — | — | — |
Root Cause
The balancer attempted to move a chunk from a shard that lost its primary replica due to network partition or replica set election failure.
generic中文
均衡器尝试从因网络分区或副本集选举失败而失去主副本的分片移动块。
Official Documentation
https://www.mongodb.com/docs/manual/core/sharding-balancer-administration/Workarounds
-
85% success Restore primary on the source shard by forcing an election: rs.stepDown() on the current primary and rs.reconfig() with appropriate priority settings, then wait for the new primary to be elected.
Restore primary on the source shard by forcing an election: rs.stepDown() on the current primary and rs.reconfig() with appropriate priority settings, then wait for the new primary to be elected.
-
80% success If the shard is permanently unavailable, remove it from the cluster: db.adminCommand({removeShard: 'shardName'}) after draining its chunks to other shards.
If the shard is permanently unavailable, remove it from the cluster: db.adminCommand({removeShard: 'shardName'}) after draining its chunks to other shards.
中文步骤
通过强制选举恢复源分片的主节点:在当前主节点上执行 rs.stepDown(),然后使用适当的优先级设置执行 rs.reconfig(),等待新主节点选举完成。
如果分片永久不可用,则将其从集群中移除:在将其块排干到其他分片后,执行 db.adminCommand({removeShard: 'shardName'})。
Dead Ends
Common approaches that don't work:
-
95% fail
Manually moving the chunk with moveChunk command fails with same error because the shard is still in recovery.
-
60% fail
Disabling the balancer (sh.stopBalancer()) stops the error but prevents data distribution, leading to uneven shard loads.