mongodb runtime_error ai_generated true

MongoServerError: ReplicaSetMonitor: 副本集 rs0 选举失败

MongoServerError: ReplicaSetMonitor: election failed for set rs0

ID: mongodb/replica-set-election-failed

其他格式: JSON · Markdown 中文 · English
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.

generic

官方文档

https://www.mongodb.com/docs/manual/reference/replica-configuration/

解决方案

  1. Force a new election by stepping down the current primary with a specific timeout: rs.stepDown(60, { force: true })
  2. Temporarily increase electionTimeoutMillis on all nodes to allow more time for consensus: cfg = rs.conf(); cfg.settings.electionTimeoutMillis = 15000; rs.reconfig(cfg)
  3. 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)

无效尝试

常见但无效的做法:

  1. 70% 失败

    Restarting nodes doesn't resolve the underlying voting deadlock; it may reset timers but the same tie condition persists.

  2. 60% 失败

    rs.stepDown() only triggers a new election without addressing the root cause of the tie.

  3. 80% 失败

    Adding more nodes doesn't automatically break ties; it requires adjusting electionTimeoutMillis or priority settings.