On this page本页内容
The priority
settings of replica set members affect both the timing and the outcome of elections for 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. The higher the number, the higher the priority.
To modify priorities, you update the members
array in the replica configuration object. The array index begins with 0
. Do not confuse this index value with the value of the replica set member’s members[n]._id
field in the array.
The value of priority
can be any floating point (i.e. decimal) number between 0
and 1000
. The default value for the priority
field is 1
.
To block a member from seeking election as primary, assign it a priority of 0
. Hidden members and delayed members have priority
set to 0
.
Changed in version 3.6.在版本3.6中更改。Starting in MongoDB 3.6, arbiters have priority 0
. When you upgrade a replica set to MongoDB 3.6, if the existing configuration has an arbiter with priority 1
, MongoDB 3.6 reconfigures the arbiter to have priority 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.priority
greater than 0 cannot have 0 votes
.As such, increasing a non-voting member’s priority
requires setting votes
to 1
and increases the number of voting replica set members. Before increasing the priority of a non-voting member, consider the following:
7 voting members
. 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 0
.0
, issue a series of replSetReconfig
or rs.reconfig()
operations to modify one member at a time. See Reconfiguration Can Add or Remove No More than One Voting Member at a Time for more information.Warning
rs.reconfig()
shell method can force the current primary to step down, which causes an election. When the primary steps down, the mongod
closes all client connections. While this typically takes 10-20 seconds, try to make these changes during scheduled maintenance periods.Change each member’s members[n].priority
value, as configured in the members
array.
This sequence of operations modifies the value of cfg
to set the priority for the first three members defined in the members
array.
Use rs.reconfig()
to apply the new configuration.
This operation updates the configuration of the replica set using the configuration defined by the value of cfg
.