Skip to content

Revise Replica Set Tutorial for Priority 0 #1869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions source/includes/steps-configure-secondary-only-rs-member.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
title: Assign the current configuration values to a variable.
stepnum: 1
ref: assign-rsconf
pre: |
In the :program:`mongo` shell, assign the :method:`rs.conf()` method to a variable:
action:
language: javascript
code: cfg = rs.conf()
---
title: Assign priority values.
stepnum: 2
ref: assign-priority-values
pre: |
For each member of the replica set, assign a priority value for the
:data:`~local.system.replset.members` array by updating the ``cfg`` variable:
action:
language: javascript
code: |
cfg.members[0].priority = 2
cfg.members[1].priority = 1
cfg.members[2].priority = 0.5
cfg.members[3].priority = 0
post: |
``0``, ``1``, ``2``, and ``3`` are the array index values, not the ``_id``
values returned by the :method:`rs.conf()` method.

This sequence of operations reconfigures the replica set with the
following priority settings:

- Member at array index ``0`` has a priority of ``2`` so that it becomes primary under most circumstances.

- Member at ``1`` has a priority of ``1``, which is the default value. Member ``1`` becomes primary if no member with a *higher* priority is eligible.

- Member at ``2`` has a priority of ``0.5``, which makes it less likely to become primary than other members but doesn't prohibit the possibility.

- Member at ``3`` has a priority of ``0``. Member at ``3`` **cannot** become the :term:`primary` member under any circumstances.
---
title: Update replica set configuration.
ref: update-replica-set-configuration
stepnum: 3
pre: |
Pass the variable with updated priority values to :method:`rs.reconfig()` method:
action:
language: javascript
code: rs.reconfig(cfg)
...
100 changes: 33 additions & 67 deletions source/tutorial/configure-secondary-only-replica-set-member.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,77 +4,43 @@ Prevent Secondary from Becoming Primary

.. default-domain:: mongodb

To prevent a :term:`secondary` member from ever becoming a
:term:`primary` in a :term:`failover`, assign the secondary a priority
of ``0``, as described here. You can set this "secondary-only mode" for
any member of the :term:`replica set`, except the current primary. For a
detailed description of secondary-only members and their purposes, see
:doc:`/core/replica-set-priority-0-member`.

To configure a member as secondary-only, set its
:data:`~local.system.replset.members[n].priority` value to ``0`` in
the :data:`~local.system.replset.members` document in its replica set
configuration. Any member with a
:data:`~local.system.replset.members[n].priority` equal to ``0`` will
never seek :ref:`election <replica-set-elections>` and cannot become
primary in any situation.

.. code-block:: javascript
:emphasize-lines: 4

{
"_id" : <num>,
"host" : <hostname:port>,
"priority" : 0
}

MongoDB does not permit the current :term:`primary` to have a priority
of ``0``. To prevent the current primary from again becoming a primary,
you must first step down the current primary using
:method:`rs.stepDown()`, and then you must :ref:`reconfigure the replica
set <replica-set-reconfiguration-usage>` with :method:`rs.conf()` and
:method:`rs.reconfig()`.

Example
-------

As an example of modifying member priorities, assume a four-member
replica set. Use the following sequence of operations to modify member
priorities in the :program:`mongo` shell connected to the primary.
Identify each member by its array index in the
:data:`~local.system.replset.members` array:

.. code-block:: javascript

cfg = rs.conf()
cfg.members[0].priority = 2
cfg.members[1].priority = 1
cfg.members[2].priority = 0.5
cfg.members[3].priority = 0
rs.reconfig(cfg)

The sequence of operations reconfigures the set with the following
priority settings:

- Member at ``0`` has a priority of ``2`` so that it becomes primary under
most circumstances.

- Member at ``1`` has a priority of ``1``, which is the default value.
Member ``1`` becomes primary if no member with a *higher* priority is
eligible.

- Member at ``2`` has a priority of ``0.5``, which makes it less likely to
become primary than other members but doesn't prohibit the
possibility.

- Member at ``3`` has a priority of ``0``.
Member at ``3`` **cannot** become the :term:`primary` member under any
circumstances.
Overview
--------

In a replica set, by default all :term:`secondary` members are eligible to
become primary through the election process. You can use the
:data:`priority <local.system.replset.members[n].priority>` to effect the
outcome of these elections by making some members more likely to become
primary and other members less likely or unable to become primary.

Secondaries that cannot become primary are also unable to trigger
elections. In all other respects these secondaries are identical to other
secondaries.

To prevent a :term:`secondary` member from ever becoming a :term:`primary`
in a :term:`failover`, assign the secondary a priority of ``0``, as
described here. For a detailed description of secondary-only members and their purposes,
see :doc:`/core/replica-set-priority-0-member`.

Considerations
--------------

.. include:: /includes/fact-rs-conf-array-index.rst

.. note::

MongoDB does not permit the current :term:`primary` to have a priority
of ``0``. To prevent the current primary from again becoming a primary,
you must first step down the current primary using
:method:`rs.stepDown()`.

Procedure
---------

.. include:: /includes/warning-rs-reconfig.rst

.. include:: /includes/steps/configure-secondary-only-rs-member.rst

Related Documents
-----------------

Expand All @@ -84,4 +50,4 @@ Related Documents

- :ref:`Replica Set Reconfiguration <replica-set-reconfiguration-usage>`

- :doc:`/core/replica-set-elections`
- :doc:`/core/replica-set-elections`