Adjust Priority for Replica Set Member调整副本集成员的优先级
On this page本页内容
Overview概述
The 副本集成员的priority
settings of replica set members affect both the timing and the outcome of elections for primary. priority
设置会影响主选举的时间和结果。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.数字越高,优先级就越高。
Considerations注意事项
To modify priorities, you update the 要修改优先级,请更新复制副本配置对象中的members
array in the replica configuration object. The array index begins with 0
. members
数组。数组索引以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 隐藏成员和延迟成员的优先级设置为0。priority
set to 0
.
Arbiters have priority 仲裁员的优先级为0
.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.在选举之前,主服务器会关闭所有打开的客户端连接。
Priority and Votes优先级和投票
members[n].priority
and 和members[n].votes
have the following relationship:具有以下关系:
Non-voting (i.e.无表决权(即votes
is0
) members must havepriority
of 0.votes
为0
)成员的priority
必须为0。Members withpriority
greater than 0 cannot have 0votes
.priority
大于0的成员不能有0票。
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:在增加无表决权成员的优先权之前,请考虑以下事项:
MongoDB replica sets can have no more than 7 voting members.MongoDB副本集的投票成员不能超过7个。If the replica set already has 7 voting members, you cannot modify the priority of any remaining members in the replica set to be greater than如果副本集中已有7个投票成员,则不能将副本集中任何剩余成员的优先级修改为大于0
.0
。Starting in MongoDB 4.4, replica reconfiguration can add or remove no more than one voting member at a time. To change multiple non-voting members to have a priority greater than从MongoDB 4.4开始,副本重新配置一次可以添加或删除不超过一个投票成员。要将多个无投票权成员更改为优先级大于0,请执行一系列0
, issue a series ofreplSetReconfig
orrs.reconfig()
operations to modify one member at a time.replSetReconfig
或rs.reconfig()
操作,一次修改一个成员。See Reconfiguration Can Add or Remove No More than One Voting Member at a Time for more information.有关详细信息,请参阅重新配置一次最多可添加或删除一个投票成员。
Procedure过程
Thers.reconfig()
shell method can force the current primary to step down, which causes an election.rs.reconfig()
shell方法可以强制当前的primary退出,从而导致选举。When the primary steps down, the当primary关闭时,mongod
closes all client connections. While this typically takes 10-20 seconds, try to make these changes during scheduled maintenance periods.mongod
会关闭所有客户端连接。虽然这通常需要10-20秒,但请尝试在计划维护期间进行这些更改。Avoid reconfiguring replica sets that contain members of different MongoDB versions as validation rules may differ across MongoDB versions.避免重新配置包含不同MongoDB版本成员的副本集,因为验证规则可能因MongoDB版本而异。
Change each member's priority value.更改每个成员的优先级值。
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
数组中定义的前三个成员的优先级。
Assign the replica set the new configuration.为复制副本集分配新配置。
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
值定义的配置更新复制副本集的配置。