mongodb
runtime_error
ai_generated
true
MongoServerError: ReplicaSetMonitor: 副本集 rs0 选举失败
MongoServerError: ReplicaSetMonitor: election failed for set rs0
ID: mongodb/replica-set-election-failed
85%修复率
85%置信度
1证据数
2023-08-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| MongoDB 5.0 | active | — | — | — |
| MongoDB 6.0 | active | — | — | — |
| MongoDB 7.0 | active | — | — | — |
根因分析
副本集选举失败,因为平局或网络分区阻止大多数节点就主节点达成一致。
English
The replica set election failed due to a tie or network partition preventing a majority of nodes from agreeing on a primary.
官方文档
https://www.mongodb.com/docs/manual/reference/replica-configuration/解决方案
-
Force a new election by stepping down the current primary with a specific timeout: rs.stepDown(60, { force: true }) -
Temporarily increase electionTimeoutMillis on all nodes to allow more time for consensus: cfg = rs.conf(); cfg.settings.electionTimeoutMillis = 15000; rs.reconfig(cfg)
-
If a tie persists, manually set a node's priority to 0 to remove it from contention, then reconfig: cfg = rs.conf(); cfg.members[1].priority = 0; rs.reconfig(cfg)
无效尝试
常见但无效的做法:
-
70% 失败
Restarting nodes doesn't resolve the underlying voting deadlock; it may reset timers but the same tie condition persists.
-
60% 失败
rs.stepDown() only triggers a new election without addressing the root cause of the tie.
-
80% 失败
Adding more nodes doesn't automatically break ties; it requires adjusting electionTimeoutMillis or priority settings.