# MongoServerError: 均衡器轮次失败：命名空间 test.users 的块迁移失败，原因：源分片没有主节点

- **ID:** `mongodb/balancer-round-failed`
- **领域:** mongodb
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

均衡器尝试从因网络分区或副本集选举失败而失去主副本的分片移动块。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| MongoDB 5.0 | active | — | — |
| MongoDB 6.0 | active | — | — |
| MongoDB 7.0 | active | — | — |

## 解决方案

1. ```
   通过强制选举恢复源分片的主节点：在当前主节点上执行 rs.stepDown()，然后使用适当的优先级设置执行 rs.reconfig()，等待新主节点选举完成。
   ```
2. ```
   如果分片永久不可用，则将其从集群中移除：在将其块排干到其他分片后，执行 db.adminCommand({removeShard: 'shardName'})。
   ```

## 无效尝试

- **** — Manually moving the chunk with moveChunk command fails with same error because the shard is still in recovery. (95% 失败率)
- **** — Disabling the balancer (sh.stopBalancer()) stops the error but prevents data distribution, leading to uneven shard loads. (60% 失败率)
