@@ -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+
4641Behavior
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
8052Examples
8153--------
@@ -86,14 +58,13 @@ Step Down with Default Options
8658The following example, run on the current primary, attempts to step
8759down 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
9062secondary to catch up. If no suitable secondary exists, the primary
9163does 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
10677an electable secondary to catch up. If no suitable secondary exists,
10778the 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
12292an electable secondary to catch up. Because of the ``force: true``
12393option, 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 } )
0 commit comments