Adjust Priority for Replica Set Member

Overview

The priority settings of replica set members affect both the timingand the outcome of elections forprimary. Higher-priority members are more likely to call elections, andare more likely to win. Use this setting to ensure that some members aremore likely to become primary and that others can never become primary.

The value of the member’spriority setting determines themember’s priority in elections. The higher the number,the higher the priority.

Considerations

To modify priorities, you update the membersarray in the replica configuration object. The array index begins with0. Do not confuse this index value with the value of the replicaset member’s members[n]._id field in thearray.

The value of priority can be anyfloating point (i.e. decimal) number between 0 and 1000. Thedefault value for the priority field is 1.

To block a member from seeking election as primary, assign it a priorityof 0. Hidden members anddelayed members havepriority set to 0.

Changed in version 3.2:

Changed in version 3.6: Starting in MongoDB 3.6, arbiters have priority 0. When you upgradea replica set to MongoDB 3.6, if the existing configuration has anarbiter with priority 1, MongoDB 3.6 reconfigures the arbiter tohave 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 openclient connections.

Procedure

Warning

  • The rs.reconfig() shell method can force the currentprimary to step down, which causes an election. When the primary steps down, themongod closes all client connections. While thistypically takes 10-20 seconds, try to make these changes duringscheduled maintenance periods.
  • Avoid reconfiguring replica sets that contain members of differentMongoDB versions as validation rules may differ across MongoDB versions.

Copy the replica set configuration to a variable.

In the mongo shell, use rs.conf() to retrievethe replica set configuration and assign it to a variable. Forexample:

  1. cfg = rs.conf()

Change each member’s priority value.

Change each member’s members[n].priorityvalue, as configured in the membersarray.

  1. cfg.members[0].priority = 0.5
  2. cfg.members[1].priority = 2
  3. cfg.members[2].priority = 2

This sequence of operations modifies the value of cfg to set thepriority for the first three members defined in themembers array.

Assign the replica set the new configuration.

Use rs.reconfig() to apply the new configuration.

  1. rs.reconfig(cfg)

This operation updates the configuration of the replica set usingthe configuration defined by the value of cfg.