Replica Set Protocol Version副本集协议版本
Starting in version 4.0, MongoDB only supports replica set protocol version 1 (从4.0版本开始,MongoDB只支持副本集协议版本1(pv1
). pv1
is the default for all new replica sets created with MongoDB 3.2 or later.pv1
)。pv1
是使用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.pv1
在MongoDB 3.2版或更高版本中可用,是使用3.2版或更新版本创建的所有新副本集的默认值。
Arbiters仲裁器
For the following MongoDB versions, 对于以下MongoDB版本,与带有仲裁器的副本集的pv1
increases the likelihood of w:1
rollbacks compared to pv0
(no longer supported in MongoDB 4.0+) for replica sets with arbiters: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, 对于以下MongoDB版本,对于具有不同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: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.个别成员可以在特定选举中投票支持或反对候选人,但不能单方面单独否决(中止)选举。s
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
,并且对前一个主要服务器的新写入最终会回滚。
pv1
uses the concept of term. This allows for a faster detection of simultaneous primaries and for multiple successful elections in a short period of time.pv1
使用了术语的概念。这允许更快地检测同时进行的初选,并在短时间内成功进行多次选举。
Back to Back Elections背靠背选举
pv1
makes a "best-effort" attempt to have the secondary with the highest priority
available call an election. This could lead to back-to-back elections as eligible members with higher priority can call an election.pv1
会“尽最大努力”让具有最高优先级的secondary进行选举。这可能会导致背靠背的选举,因为具有更高优先级的合格成员可以举行选举。
However, in MongoDB 3.6+ (as well as MongoDB 3.4.2+ and 3.2.12+), for 然而,在MongoDB 3.6+(以及MongoDB 3.4.2+和3.2.12+)中,对于pv1
: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 (从4.0版本开始,MongoDB只支持副本集协议版本1(pv1
).pv1
)。
However, MongoDB 3.2 through MongoDB 3.6 support replica set protocol version 但是,MongoDB 3.2到MongoDB 3.6支持副本集协议版本1
and protocol version 0
.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
, thet
is equal to-1
.0
,则t
等于-1
。If the current replica set protocol version is如果当前副本集协议版本为1
, thet
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
写入之间进行优先级排序。