Skip to content

Commit 80f3eff

Browse files
jdestefano-mongokay-kim
authored andcommitted
DOCS-10844 - Writes now fail instead of getting blocked when running replSetStepDown or rs.stepDown().
1 parent cfc66cb commit 80f3eff

File tree

5 files changed

+94
-91
lines changed

5 files changed

+94
-91
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.. note::
2+
3+
All writes to the primary fail during the period starting when the
4+
|command-method-name| |command-method| is received until either a new
5+
primary is elected, or if there are no electible secondaries, the
6+
original primary resumes normal operation. The time period where
7+
writes fail is at maximum:
8+
9+
``secondaryCatchUpPeriodSecs`` (10s by default) +
10+
:rsconf:`~settings.electionTimeoutMillis` (10s by default).

source/includes/stepdown-behavior.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.. versionadded:: 3.0
2+
3+
The |command-method-name| |command-method| attempts to
4+
terminate long running user operations that block the primary
5+
from stepping down, such as an index build, a write operation or a
6+
map-reduce job.
7+
8+
The |command-method| then initiates a catchup period where it waits up to
9+
``secondaryCatchUpPeriodSeconds``, by default 10 seconds, for a
10+
secondary to become up-to-date with the primary. The primary only steps
11+
down if a secondary is up-to-date with the primary during the
12+
catchup period to prevent :doc:`rollbacks </core/replica-set-rollbacks>`.
13+
14+
If no electable secondary meets this criterion by the end of the waiting
15+
period, the primary does not step down and the |command-method| errors.
16+
|force-option|
17+
18+
Once the primary steps down successfully, that node cannot become the
19+
primary for the remainder of the |stepdown-secs| period,
20+
which began when the node received the |command-method|. The
21+
|command-method-name| |command-method| forces all clients currently
22+
connected to the database to disconnect. This helps ensure that the
23+
clients maintain an accurate view of the replica set.
24+
25+
Because the disconnect includes the connection used to run the
26+
|command-method|, you cannot retrieve the return status of the
27+
|command-method| if the |command-method| completes successfully. You can
28+
only retrieve the return status of the |command-method| if it errors.
29+
When running the |command-method| in a script, the script should account
30+
for this behavior.

source/includes/stepdown-intro.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Instructs the :term:`primary` of the replica set to become a
2+
:term:`secondary`. After the primary steps down, eligble secondaries will
3+
hold an :ref:`election for primary <replica-set-election-internals>`.
4+
5+
The |command-method| does not immediately step down the primary. If no
6+
:data:`electable <~replSetGetConfig.members[n].priority>` secondaries
7+
are up to date with the primary, the primary waits up to
8+
``secondaryCatchUpPeriodSecs`` (by default 10 seconds) for a
9+
secondary to catch up. Once an electable secondary is
10+
available, the |command-method| steps down the primary.
11+
12+
Once stepped down, the original primary becomes a secondary and is
13+
ineligible from becoming primary again for the remainder of time
14+
specified by |stepdown-secs|.
15+
16+
For a detailed explanation of the |command-method| 's execution,
17+
see |behavior-ref|.
18+
19+
.. note::
20+
21+
The |command-method| is only valid against the primary and throws an
22+
error if run on a non-primary member.

source/reference/command/replSetStepDown.txt

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,18 @@ Description
1515

1616
.. dbcommand:: replSetStepDown
1717

18-
Forces the :term:`primary` of the replica set to become a
19-
:term:`secondary`, triggering an :ref:`election for primary
20-
<replica-set-election-internals>`. The command steps down the
21-
primary for a specified number of seconds; during this period, the
22-
stepdown member is ineligible from becoming primary.
23-
24-
By default, the command only steps down the primary if an
25-
:data:`electable <~replSetGetConfig.members[n].priority>`
26-
secondary is up-to-date with the primary, waiting up to 10 seconds
27-
for a secondary to catch up.
28-
29-
The command is only valid against the primary and will error if run
30-
on a non-primary member. :dbcommand:`replSetStepDown` can
31-
only run in the ``admin`` database and has the following prototype
32-
form:
18+
.. |command-method| replace:: command
19+
.. |stepdown-secs| replace:: ``replSetStepDown: <seconds>``
20+
.. |behavior-ref| replace:: :ref:`replSetStepDown-behavior`
21+
22+
.. include:: /includes/stepdown-intro.rst
23+
24+
The :dbcommand:`replSetStepDown` can only run on the ``admin`` database
25+
and has the following prototype form:
3326

3427
.. code-block:: javascript
3528

36-
db.runCommand( {
29+
db.adminCommand( {
3730
replSetStepDown: <seconds>,
3831
secondaryCatchUpPeriodSecs: <seconds>,
3932
force: <true|false>
@@ -43,39 +36,18 @@ Description
4336

4437
.. include:: /includes/apiargs/command-replSetStepDown-field.rst
4538

39+
.. _replSetStepDown-behavior:
40+
4641
Behavior
4742
--------
4843

49-
.. versionadded:: 3.0
50-
51-
Before stepping down, :dbcommand:`replSetStepDown` will attempt to
52-
terminate long running user operations that would block the primary
53-
from stepping down, such as an index build, a write operation or a
54-
map-reduce job.
55-
56-
To avoid rollbacks, :dbcommand:`replSetStepDown`, by default, only
57-
steps down the primary if an electable secondary is completely caught up
58-
with the primary. The command will wait up to the
59-
``secondaryCatchUpPeriodSecs`` for a secondary to catch up.
44+
.. |force-option| replace:: You can override this behavior and issue with command with the ``force: true`` option to immediately step down the primary.
6045

61-
If no electable secondary meets this criterion by the waiting period,
62-
the primary does not step down and the command errors. However, you can
63-
override this behavior by including the ``force: true`` option.
46+
.. |command-method-name| replace:: :dbcommand:`replSetStepDown`
6447

65-
Upon successful stepdown, :dbcommand:`replSetStepDown` forces all
66-
clients currently connected to the database to disconnect. This helps
67-
ensure that the clients maintain an accurate view of the replica set.
48+
.. include:: /includes/stepdown-behavior.rst
6849

69-
Because the disconnect includes the connection used to run the command,
70-
you cannot retrieve the return status of the command if the command
71-
completes successfully; i.e. you can only retrieve the return status of
72-
the command if it errors. When running the command in a script, the
73-
script should account for this behavior.
74-
75-
.. note::
76-
77-
:dbcommand:`replSetStepDown` blocks all writes to the primary while
78-
it runs.
50+
.. include:: /includes/fact-stepdown-write-fail.rst
7951

8052
Examples
8153
--------
@@ -86,14 +58,13 @@ Step Down with Default Options
8658
The following example, run on the current primary, attempts to step
8759
down the member for ``120`` seconds.
8860

89-
The operation will wait up to the default ``10`` seconds for a
61+
The operation waits up to the default ``10`` seconds for a
9062
secondary to catch up. If no suitable secondary exists, the primary
9163
does not step down and the command errors.
9264

93-
.. note::
94-
95-
The command blocks all writes to the primary while it runs.
65+
.. include:: /includes/fact-stepdown-write-fail.rst
9666

67+
.. class:: copyable-code
9768
.. code-block:: javascript
9869

9970
db.adminCommand( { replSetStepDown: 120 } )
@@ -106,10 +77,9 @@ down the member for ``120`` seconds, waiting up to ``15`` seconds for
10677
an electable secondary to catch up. If no suitable secondary exists,
10778
the primary does not step down and the command errors.
10879

109-
.. note::
110-
111-
The command blocks all writes to the primary while it runs.
80+
.. include:: /includes/fact-stepdown-write-fail.rst
11281

82+
.. class:: copyable-code
11383
.. code-block:: javascript
11484

11585
db.adminCommand( { replSetStepDown: 120, secondaryCatchUpPeriodSecs: 15 } )
@@ -122,10 +92,9 @@ down the member for ``120`` seconds, waiting up to ``15`` seconds for
12292
an electable secondary to catch up. Because of the ``force: true``
12393
option, the primary steps down even if no suitable secondary exists.
12494

125-
.. note::
126-
127-
The command blocks all writes to the primary while it runs.
95+
.. include:: /includes/fact-stepdown-write-fail.rst
12896

97+
.. class:: copyable-code
12998
.. code-block:: javascript
13099

131100
db.adminCommand( { replSetStepDown: 120, secondaryCatchUpPeriodSecs: 15, force: true } )

source/reference/method/rs.stepDown.txt

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,11 @@ Description
1515

1616
.. method:: rs.stepDown(stepDownSecs, secondaryCatchUpPeriodSecs)
1717

18-
Triggers the :term:`primary` of the replica set to become a
19-
:term:`secondary`. This in turn triggers an :ref:`election for primary
20-
<replica-set-election-internals>`. The method steps down the primary
21-
for a specified number of seconds; during this period, the stepdown
22-
member is ineligible from becoming primary.
18+
.. |command-method| replace:: method
19+
.. |stepdown-secs| replace:: ``stepDownSecs``
20+
.. |behavior-ref| replace:: :ref:`rs.stepDown-behavior`
2321

24-
The method only steps down the primary if an :data:`electable
25-
<~replSetGetConfig.members[n].priority>` secondary is up-to-date
26-
with the primary, waiting up to 10 seconds, by default, for a secondary to catch
27-
up.
28-
29-
The method is only valid against the primary and will error if run
30-
on a non-primary member.
22+
.. include:: /includes/stepdown-intro.rst
3123

3224
The :method:`rs.stepDown()` method has the following parameters:
3325

@@ -36,35 +28,15 @@ Description
3628
:method:`rs.stepDown()` provides a wrapper around the
3729
command :dbcommand:`replSetStepDown`.
3830

31+
.. _rs.stepDown-behavior:
32+
3933
Behavior
4034
--------
4135

42-
.. versionadded:: 3.0
43-
44-
Before stepping down, :method:`rs.stepDown()` will attempt to
45-
terminate long running user operations that would block the primary
46-
from stepping down, such as an index build, a write operation or a
47-
map-reduce job.
48-
49-
To avoid rollbacks, :method:`rs.stepDown()`, by default, only
50-
steps down the primary if an electable secondary is completely caught up
51-
with the primary. The command will wait up to either 10 seconds or the
52-
``secondaryCatchUpPeriodSecs`` for a secondary to catch up.
53-
54-
If no electable secondary meets this criterion by the waiting period,
55-
the primary does not step down and the method throws an exception.
56-
57-
Upon successful stepdown, :method:`rs.stepDown()` forces all
58-
clients currently connected to the database to disconnect. This helps
59-
ensure that the clients maintain an accurate view of the replica set.
36+
.. |force-option| replace:: \
6037

61-
Because the disconnect includes the connection used to run the command,
62-
you cannot retrieve the return status of the command if the command
63-
completes successfully; i.e. you can only retrieve the return status of
64-
the command if it errors. When running the command in a script, the
65-
script should account for this behavior.
38+
.. |command-method-name| replace:: :method:`rs.stepDown()`
6639

67-
.. note::
40+
.. include:: /includes/stepdown-behavior.rst
6841

69-
:method:`rs.stepDown()` blocks all writes to the primary while it
70-
runs.
42+
.. include:: /includes/fact-stepdown-write-fail.rst

0 commit comments

Comments
 (0)