Starting in version 4.0, MongoDB only supports replica set protocol version 1 (从4.0版开始,MongoDB仅支持副本集协议版本1(pv1
). pv1
)。pv1
is the default for all new replica sets created with MongoDB 3.2 or later.是使用MongoDB 3.2或更高版本创建的所有新副本集的默认值。
w:1
WritesWith 对于pv1
, you can use catchUpTimeoutMillis
to prioritize between faster failovers and preservation of w:1
writes.pv1
,您可以使用catchUpTimeoutMillis
在更快的故障切换和w:1
写入保存之间进行优先级排序。
w: "majority"
pv1
guarantees the preservation of confirmed w:"majority"
writes.pv1
保证保存已确认的w:"majority"
写道。
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版或更新版本创建的所有新副本集的默认设置。
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
回滚的可能性:
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
回滚的可能性。
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
回滚的可能性:
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
回滚的可能性。
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.个别成员可以在特定选举中投票支持或反对候选人,但不能单方面否决(中止)选举。
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.这允许更快地检测同时进行的初选,并在短时间内多次成功举行选举。
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 然而,在MongoDB 3.6+(以及MongoDB 3.4.2+和3.2.12+)中,对于pv1
:pv1
:
pv1
prevents double voting in one member's call for election. 防止在一名成员的选举呼吁中进行双重投票。This is achieved through its use of terms.这是通过使用术语实现的。
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
0
, the t
is equal to -1
.0
,则t
等于-1
。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
写入保留之间进行优先级排序。