Skip to content

Commit e39c748

Browse files
author
Bob Grabar
committed
DOCS-508 new procedure
1 parent 748a74f commit e39c748

File tree

2 files changed

+91
-13
lines changed

2 files changed

+91
-13
lines changed

source/replication.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ operations in detail:
4949
tutorial/expand-replica-set
5050
tutorial/deploy-geographically-distributed-replica-set
5151
tutorial/change-oplog-size
52-
tutorial/force-member-to-be-primary`
52+
tutorial/force-member-to-be-primary
5353
tutorial/change-hostnames-in-a-replica-set
5454
tutorial/convert-secondary-into-arbiter
5555

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,102 @@
1-
==========================
2-
For a Member to be Primary
3-
==========================
1+
================================
2+
Force a Member to Become Primary
3+
================================
44

55
.. default-domain:: mongodb
66

77
Synopsis
88
--------
99

10-
You can force a member to be :term:`primary` by giving it a higher
11-
:data:`members[n].priority` value than any other member in the
12-
:term:`replica set`. You can also force :term:`secondary` members never
13-
to become primary by setting their :data:`members[n].priority` values to
14-
``0``, which means they can never seek :ref:`election
15-
<replica-set-elections>` as primary. For more information on priority
16-
levels, see :ref:`replica-set-node-priority`.
10+
You can force a :term:`replica set` member to become :term:`primary` by
11+
giving it a higher :data:`members[n].priority` value than any other
12+
member in the set. Optionally, you also can force all :term:`secondary`
13+
members never to become primaries by setting their
14+
:data:`members[n].priority` values to ``0``, which means they can never
15+
seek :ref:`election <replica-set-elections>` as primary. Or, as
16+
different approach, you can instead set all secondary members to be
17+
secondary-only, as described in
18+
:ref:`replica-set-secondary-only-members`.
1719

1820
Procedures
1921
----------
2022

2123
.. _replica-set-force-member-to-be-primary-via-priority-setting:
2224

23-
Force a Member to be Primary by Setting it Priority High
24-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25+
Force a Member to be Primary by Setting its Priority High
26+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27+
28+
For this procedure, assume your current :term:`primary` is
29+
``m1.example.net`` and you'd like to force ``m3.example.net`` to be
30+
primary. Also assume you have a three-member :term:`replica set` with the
31+
following configuration:
32+
33+
.. code-block:: javascript
34+
35+
{
36+
"_id" : "rs",
37+
"version" : 7,
38+
"members" : [
39+
{
40+
"_id" : 0,
41+
"host" : "m1.example.net:27017"
42+
},
43+
{
44+
"_id" : 1,
45+
"host" : "m2.example.net:27017"
46+
},
47+
{
48+
"_id" : 2,
49+
"host" : "m3.example.net:27017"
50+
}
51+
]
52+
}
53+
54+
1. In the :program:`mongo` shell, use the following sequence of operations
55+
to make ``m3.example.net`` the primary:
56+
57+
.. code-block:: javascript
58+
59+
cfg = rs.conf()
60+
cfg.members[0].priority = 0.5
61+
cfg.members[1].priority = 0.5
62+
cfg.members[2].priority = 1
63+
rs.reconfig(cfg)
64+
65+
This sets ``m3.example.net`` to have a higher
66+
:data:`members[n].priority` value than the other :program:`mongod`
67+
instances.
68+
69+
The following sequence of events occur:
70+
71+
- ``m3.example.net`` and ``m2.example.net`` sync with
72+
``m1.example.net`` (typically within 10 seconds).
73+
74+
- ``m1.example.net`` sees that it no longer has highest priority and,
75+
in most cases, steps down. If ``m3.example.net`` is far behind
76+
``m1.example.net``, ``m1.example.net`` does not step down until
77+
``m3.example.net`` is within 10 seconds of it's :ref:`optime
78+
<members.optime>`. This minimizes the amount of time with no
79+
primary on failover.
80+
81+
- The step down forces on election in which ``m3.example.net``
82+
becomes primary based on its :data:`members[n].priority` value.
83+
84+
#. Optionally, if ``m3.example.net`` is more than 10 seconds behind
85+
``m1.example.net``'s optime, and if you don't need to have a primary
86+
designated within 10 seconds, you can force ``m1.example.net`` to step down by running:
87+
88+
.. code-block:: javascript
89+
90+
db.adminCommand({replSetStepDown:1000000, force:1})
91+
92+
This prevents ``m1.example.net`` from being primary for 1,000,000
93+
seconds, even if there is no other member that can become primary.
94+
When ``m3.example.net`` catches up with ``m1.example.net`` it syncs
95+
and becomes primary.
96+
97+
If you change your mind and would like to make ``m1.example.net`` primary again while it waits for
98+
``m3.example.net`` to catch up, issue the following command to make ``m1.example.net`` seek election again:
99+
100+
.. code-block:: javascript
101+
102+
db.adminCommand({replSetFreeze:0})

0 commit comments

Comments
 (0)