Replica Set Protocol Version副本集协议版本

Starting in version 4.0, MongoDB only supports replica set protocol version 1 (pv1). 从4.0版开始,MongoDB仅支持副本集协议版本1(pv1)。pv1 is the default for all new replica sets created with MongoDB 3.2 or later.是使用MongoDB 3.2或更高版本创建的所有新副本集的默认值。

Preservation of Writes写入的保存

w:1 Writes

With pv1, you can use catchUpTimeoutMillis to prioritize between faster failovers and preservation of w:1 writes.对于pv1,您可以使用catchUpTimeoutMillis在更快的故障切换和w:1写入保存之间进行优先级排序。

w: "majority" Writes写入

pv1 guarantees the preservation of confirmed w:"majority" writes.pv1保证保存已确认的w:"majority"写道。

Availability可用性

pv1 is available in MongoDB version 3.2 or later and is the default for all new replica sets created with version 3.2 or later.在MongoDB 3.2版或更高版本中可用,是使用3.2版或更新版本创建的所有新副本集的默认设置。

Arbiters仲裁员

For the following MongoDB versions, pv1 increases the likelihood of w:1 rollbacks compared to pv0(no longer supported in MongoDB 4.0+) for replica sets with arbiters:对于以下MongoDB版本,对于具有仲裁器的副本集,与pv0(MongoDB 4.0+不再支持)相比,pv1增加了w:1回滚的可能性:

  • MongoDB 3.4.1
  • MongoDB 3.4.0
  • MongoDB 3.2.11 or earlier

For the other versions of MongoDB that support pv1, pv1 does not increase the likelihood of w:1 rollbacks for replica sets with arbiters.对于其他支持pv1的MongoDB版本,pv1不会增加具有仲裁器的副本集w:1回滚的可能性。

Priorities优先事项

For the following MongoDB versions, pv1 increases the likelihood of w:1 rollbacks compared to pv0(no longer supported in MongoDB 4.0+) for replica sets with different members[n].priority settings:对于以下MongoDB版本,对于具有不同members[n].priority设置的副本集,与pv0(MongoDB 4.0+不再支持)相比,pv1增加了w:1回滚的可能性:

  • MongoDB 3.4.1
  • MongoDB 3.4.0
  • MongoDB 3.2.11 or earlier

For the other versions of MongoDB that support pv1, pv1 does not increase the likelihood of w:1 rollbacks for replica sets with different members[n].priority settings.对于其他支持pv1的MongoDB版本,pv1不会增加具有不同members[n].priority设置的副本集w:1回滚的可能性。

Vetoes

pv1 does not use vetoes. 不使用否决权。Individual members can vote for or against a candidate in a particular election, but cannot individually veto (abort) an election unilaterally.个别成员可以在特定选举中投票支持或反对候选人,但不能单方面否决(中止)选举。

Detection of Simultaneous Primaries同时原语的检测

In some circumstances, two nodes in a replica set may transiently believe that they are the primary, but at most, one of them will be able to complete writes with { w: "majority" } write concern. 某些情况下,副本集中的两个节点可能会暂时认为自己是主节点,但最多只有一个节点能够完成写操作,而不必担心{ w: "majority" }写操作。The node that can complete { w: "majority" } writes is the current primary, and the other node is a former primary that has not yet recognized its demotion, typically due to a network partition. 可以完成{ w: "majority" }写入的节点是当前主节点,而另一个节点是尚未识别其降级的前主节点,通常是由于网络分区When this occurs, clients that connect to the former primary may observe stale data despite having requested read preference primary, and new writes to the former primary will eventually roll back.发生这种情况时,连接到前一个主服务器的客户端可能会观察到过时的数据,尽管请求了读取首选项primary,但对前一个primary的新写入最终会回滚。

pv1 uses the concept of term. pv1使用术语的概念。This allows for a faster detection of simultaneous primaries and for multiple successful elections in a short period of time.这允许更快地检测同时进行的初选,并在短时间内多次成功举行选举。

Back to Back Elections背靠背选举

pv1 makes a "best-effort" attempt to have the secondary with the highest priority available call an election. 尽“最大努力”让priority最高的secondary进行选举。This could lead to back-to-back elections as eligible members with higher priority can call an election.这可能导致连续选举,因为具有较高优先权的合格成员可以要求选举。

However, in MongoDB 3.6+ (as well as MongoDB 3.4.2+ and 3.2.12+), for pv1:然而,在MongoDB 3.6+(以及MongoDB 3.4.2+和3.2.12+)中,对于pv1

  • Priority elections have been limited to occur only if the higher priority node is within 10 seconds of the current primary.优先级选举被限制为仅当优先级较高的节点在当前初选的10秒内时发生。
  • Arbiters will vote no in elections if they detect a healthy primary of equal or greater priority to the candidate.如果仲裁员发现一场与候选人同等或更优先的健康初选,他们将在选举中投反对票。

Double Voting双重投票

pv1 prevents double voting in one member's call for election. 防止在一名成员的选举呼吁中进行双重投票。This is achieved through its use of terms.这是通过使用术语实现的。

Modify Replica Set Protocol Version修改副本集协议版本

Starting in version 4.0, MongoDB only supports replica set protocol version 1 (pv1).从4.0版开始,MongoDB仅支持副本集协议版本1(pv1)。

However, MongoDB 3.2 through MongoDB 3.6 support replica set protocol version 1 and protocol version 0.但是,MongoDB 3.2到MongoDB 3.6支持副本集协议版本1和协议版本0

Before changing the protocol version for MongoDB 3.2 through MongoDB 3.6, ensure that at least one oplog entry (generated from the current protocol version) has replicated from the primary to all secondaries. 在更改MongoDB 3.2到MongoDB 3.6的协议版本之前,请确保至少有一个oplog条目(从当前协议版本生成)已从主服务器复制到所有辅助服务器。To check, on each secondary, check the optimes.lastCommittedOpTime.t field returned from rs.status(). 要进行检查,请检查从rs.status()返回的optimes.lastCommittedOpTime.t字段。For example, connect mongosh to each secondary and run:例如,将mongosh连接到每个辅助服务器并运行:

rs.status().optimes.lastCommittedOpTime.t
  • If the current replica set protocol version is 0, the t is equal to -1.如果当前副本集协议版本为0,则t等于-1
  • If the current replica set protocol version is 1, the t is greater than -1.如果当前副本集协议版本为1,则t大于-1

Once you have verified that at least one oplog entry (using the current protocol version) has replicated to all the secondaries, you can change the protocol version.验证至少有一个oplog条目(使用当前协议版本)已复制到所有辅助服务器后,可以更改协议版本。

To change the replica set protocol version, reconfigure (rs.reconfig()) the replica set with the new protocolVersion. 要更改副本集协议版本,请使用新的protocolVersion重新配置(rs.reconfig())副本集。For example, to upgrade to pv1, connect mongosh to the current primary and perform the following sequence of operations:例如,要升级到pv1,请将mongosh连接到当前主服务器并执行以下操作序列:

cfg = rs.conf();
cfg.protocolVersion=1;
rs.reconfig(cfg);

You can use catchUpTimeoutMillis to prioritize between faster failovers and preservation of w:1 writes.您可以使用catchUpTimeoutMillis在更快的故障切换和w:1写入保留之间进行优先级排序。

←  Replica Set ConfigurationTroubleshoot Replica Sets →