mongodb
runtime_error
ai_generated
partial
MongoServerError: 均衡器轮次失败:命名空间 test.users 的块迁移失败,原因:源分片没有主节点
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%修复率
85%置信度
1证据数
2025-03-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| MongoDB 5.0 | active | — | — | — |
| MongoDB 6.0 | active | — | — | — |
| MongoDB 7.0 | active | — | — | — |
根因分析
均衡器尝试从因网络分区或副本集选举失败而失去主副本的分片移动块。
English
The balancer attempted to move a chunk from a shard that lost its primary replica due to network partition or replica set election failure.
官方文档
https://www.mongodb.com/docs/manual/core/sharding-balancer-administration/解决方案
-
通过强制选举恢复源分片的主节点:在当前主节点上执行 rs.stepDown(),然后使用适当的优先级设置执行 rs.reconfig(),等待新主节点选举完成。
-
如果分片永久不可用,则将其从集群中移除:在将其块排干到其他分片后,执行 db.adminCommand({removeShard: 'shardName'})。
无效尝试
常见但无效的做法:
-
95% 失败
Manually moving the chunk with moveChunk command fails with same error because the shard is still in recovery.
-
60% 失败
Disabling the balancer (sh.stopBalancer()) stops the error but prevents data distribution, leading to uneven shard loads.