On this page本页内容
The 复制集成员的priority
settings of replica set members affect both the timing and the outcome of elections for primary. priority
设置影响primary选举的时间和结果。Higher-priority members are more likely to call elections, and are more likely to win. 优先级较高的成员更有可能举行选举,也更有可能获胜。Use this setting to ensure that some members are more likely to become primary and that others can never become primary.使用此设置可确保某些成员更有可能成为主要成员,而其他成员永远不会成为主要成员。
The value of the member's 成员的priority
setting determines the member's priority
in elections. priority
设置值决定了成员在选举中的priority
。The higher the number, the higher the priority.数字越高,优先级越高。
To modify priorities, you update the 要修改优先级,请更新副本配置对象中的members
array in the replica configuration object. members
数组。The array index begins with 数组索引以0
. 0
开头。Do not confuse this index value with the value of the replica set member's 不要将此索引值与数组中的副本集成员的members[n]._id
field in the array.members[n]._id
字段混淆。
The value of priority
can be any floating point (i.e. decimal) number between 0
and 1000
. priority
的值可以是0
到1000
之间的任何浮点(即十进制)数字。The default value for the priority
field is 1
.priority
字段的默认值为1
。
To block a member from seeking election as primary, assign it a priority of 若要阻止成员寻求初选,请为其分配优先级0
. 0
。Hidden members and delayed members have 隐藏成员和延迟成员的priority
set to 0
.priority
设置为0
。
Changed in version 3.6.在版本3.6中更改。
0
. 0
。1
, MongoDB 3.6 reconfigures the arbiter to have priority 0
.1
的仲裁器,MongoDB 3.6会将仲裁器重新配置为优先级为0
。
Adjust priority settings during a scheduled maintenance window. 在定期维护窗口期间调整优先级设置。Reconfiguring priority can force the current primary to step down, leading to an election. 重新配置优先级可能会迫使当前的初选下台,从而导致选举。Before an election, the primary closes all open client connections.在选举之前,主服务器将关闭所有打开的客户端连接。
members[n].priority
and 和members[n].votes
have the following relationship:具有以下关系:
votes
is 0
) members must have priority
of 0.votes
是0
)成员的priority
必须为0。priority
greater than 0 cannot have 0 votes
.priority
大于0的成员不能有0votes
。As such, increasing a non-voting member's 因此,增加无投票权成员的priority
requires setting votes
to 1
and increases the number of voting replica set members. priority
需要将votes
设置为1
,并增加投票副本集成员的数量。Before increasing the priority of a non-voting member, consider the following:在增加无表决权成员的优先权之前,请考虑以下事项:
0
.0
。0
, issue a series of replSetReconfig
or rs.reconfig()
operations to modify one member at a time. 0
,请执行一系列replSetReconfig
或rs.reconfig()
操作,一次修改一个成员。rs.reconfig()
shell method can force the current primary to step down, which causes an election. rs.reconfig()
shell方法可以强制当前的初选下台,从而导致选举。mongod
closes all client connections. mongod
关闭所有客户端连接。Change each member's 根据members[n].priority
value, as configured in the members
array.members
数组中的配置,更改每个成员的members[n].priority
值。
cfg.members[0].priority = 0.5 cfg.members[1].priority = 2 cfg.members[2].priority = 2
This sequence of operations modifies the value of 此操作序列修改cfg
to set the priority for the first three members defined in the members
array.cfg
的值,以设置members
数组中定义的前三个成员的优先级。
Use 使用rs.reconfig()
to apply the new configuration.rs.reconfig()
应用新配置。
rs.reconfig(cfg)
This operation updates the configuration of the replica set using the configuration defined by the value of 此操作使用cfg
.cfg
值定义的配置更新副本集的配置。