Skip to content

Commit 2982f2b

Browse files
jason-price-mongodbandf-mongodb
authored andcommitted
DOCSP-10113 Quiesce mode for short running operations
1 parent ba1351c commit 2982f2b

File tree

5 files changed

+142
-33
lines changed

5 files changed

+142
-33
lines changed

source/includes/quiesce-period.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Starting in MongoDB 5.0, :binary:`~bin.mongod` and :binary:`~bin.mongos`
2+
enter a quiesce period to allow any ongoing database operations to
3+
complete before shutting down.
4+
5+
If a :binary:`~bin.mongod` :term:`primary` receives a shut down request,
6+
the primary:
7+
8+
#. Attempts to step down to a :term:`secondary`.
9+
10+
If the step down fails and a:
11+
12+
- :dbcommand:`shutdown` or :method:`db.shutdownServer()` command
13+
was run, :binary:`~bin.mongod` only continues the shut down steps
14+
if the |force| field is true, or a
15+
16+
- ``SIGTERM`` signal was sent to :binary:`~bin.mongod`,
17+
:binary:`~bin.mongod` always continues the shut down steps.
18+
19+
#. Enters the quiesce period.
20+
21+
#. Ends any remaining database operations.
22+
23+
#. Shuts down.
24+
25+
For a :binary:`~bin.mongod` :term:`secondary` or :binary:`~bin.mongos`
26+
shut down request, the quiesce period is entered after a shut down was
27+
requested.
28+
29+
The quiesce period is specified by the:
30+
31+
- |timeout| field if a :dbcommand:`shutdown` or
32+
:method:`db.shutdownServer()` command was run, or
33+
34+
- :parameter:`shutdownTimeoutMillisForSignaledShutdown` server
35+
parameter if a ``SIGTERM`` signal was sent to :binary:`~bin.mongod`,
36+
or
37+
38+
- :parameter:`mongosShutdownTimeoutMillisForSignaledShutdown` server
39+
parameter if a ``SIGTERM`` signal was sent to :binary:`~bin.mongos`.
40+
41+
The |timeout| field defaults to ``15`` seconds in MongoDB 5.0.
42+
43+
Clients cannot open new connections to a :binary:`~bin.mongod` or
44+
:binary:`~bin.mongos` that is shutting down.

source/reference/command/shutdown.txt

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ shutdown
1010
:depth: 1
1111
:class: singlecol
1212

13+
.. versionchanged:: 5.0
14+
1315
.. dbcommand:: shutdown
1416

1517
The :dbcommand:`shutdown` command cleans up all database resources
1618
and then terminates the process. You must issue
1719
the :dbcommand:`shutdown` command against the :term:`admin database`.
1820

19-
The command has the following syntax:
21+
The command has this syntax:
2022

2123
.. code-block:: javascript
2224

@@ -27,7 +29,7 @@ shutdown
2729
comment: <any>
2830
})
2931

30-
The command takes the following optional field:
32+
The command takes these fields:
3133

3234
.. list-table::
3335
:header-rows: 1
@@ -47,19 +49,29 @@ shutdown
4749
- .. _shutdown-cmd-force:
4850

4951
Optional. Specify ``true`` to force the :binary:`~bin.mongod`
50-
to shut down. Force shutdown interrupts any ongoing operations
51-
on the :binary:`~bin.mongod` and may result in unexpected
52+
or :binary:`~bin.mongos` to shut down. Force shutdown
53+
interrupts any ongoing operations on the :binary:`~bin.mongod`
54+
or :binary:`~bin.mongos` and may result in unexpected
5255
behavior.
5356

5457
* - :ref:`timeoutSecs <shutdown-cmd-timeoutSecs>`
5558

5659
- .. _shutdown-cmd-timeoutSecs:
5760

58-
Optional. The number of seconds the :term:`primary` should
59-
wait for a secondary to catch up. Defaults to ``10``.
61+
Optional.
62+
63+
.. _shutdown-cmd-quiesce-period:
64+
65+
.. |force| replace:: :ref:`force <shutdown-cmd-force>`
66+
.. |timeout| replace:: :ref:`timeoutSecs <shutdown-cmd-timeoutSecs>`
6067

61-
If no secondaries catch up within the specified time, the
62-
command fails.
68+
.. include:: /includes/quiesce-period.rst
69+
70+
In MongoDB 4.4 and earlier, for a :binary:`~bin.mongod`
71+
:term:`primary`, :ref:`timeoutSecs <shutdown-cmd-timeoutSecs>`
72+
is the number of seconds the :term:`primary` should wait for a
73+
secondary to catch up. If no secondaries catch up within the
74+
specified time, the command fails. Defaults to ``10`` seconds.
6375

6476
* - ``comment``
6577

@@ -93,17 +105,19 @@ certain operations such as :ref:`index builds
93105
:ref:`force: true <shutdown-cmd-force>` to force the member
94106
to interrupt those operations and shut down.
95107

96-
Shutting Down the Replica Set Primary
97-
`````````````````````````````````````
108+
Shutting Down the Replica Set Primary, Secondary, or ``mongos``
109+
```````````````````````````````````````````````````````````````
110+
111+
.. include:: /includes/quiesce-period.rst
98112

99-
If running :dbcommand:`shutdown` against the replica set
100-
:term:`primary`, the operation implicitly uses
113+
In MongoDB 4.4 and earlier, if running :dbcommand:`shutdown` against the
114+
replica set :term:`primary`, the operation implicitly uses
101115
:dbcommand:`replSetStepDown` to step down the primary before shutting
102116
down the :binary:`~bin.mongod`. If no secondary in the replica set can
103117
catch up to the primary within ``10`` seconds, the shutdown operation
104-
fails. You can issue :dbcommand:`shutdown` with
105-
:ref:`force: true <shutdown-cmd-force>` to shut down the primary
106-
*even if* the step down fails.
118+
fails. You can issue :dbcommand:`shutdown` with :ref:`force: true
119+
<shutdown-cmd-force>` to shut down the primary *even if* the step down
120+
fails.
107121

108122
.. warning::
109123

source/reference/method/db.shutdownServer.txt

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ db.shutdownServer()
1010
:depth: 1
1111
:class: singlecol
1212

13+
.. versionchanged:: 5.0
14+
1315
.. method:: db.shutdownServer()
1416

1517
Shuts down the current :binary:`~bin.mongod` or :binary:`~bin.mongos`
1618
process cleanly and safely. You must issue the
1719
:method:`db.shutdownServer()` operation against the
1820
:term:`admin database`.
1921

20-
:method:`db.shutdownServer()` has the following syntax:
22+
:method:`db.shutdownServer()` has this syntax:
2123

2224
.. code-block:: javascript
2325

@@ -26,7 +28,7 @@ db.shutdownServer()
2628
timeoutSecs: <int>
2729
})
2830

29-
The method takes the following optional field:
31+
The method takes these fields:
3032

3133
.. list-table::
3234
:header-rows: 1
@@ -40,19 +42,30 @@ db.shutdownServer()
4042
- .. _shutdownServer-method-force:
4143

4244
Optional. Specify ``true`` to force the :binary:`~bin.mongod`
43-
to shut down. Force shutdown interrupts any ongoing
44-
operations on the :binary:`~bin.mongod` and may result in
45-
unexpected behavior.
45+
or :binary:`~bin.mongos` to shut down. Force shutdown
46+
interrupts any ongoing operations on the :binary:`~bin.mongod`
47+
or :binary:`~bin.mongos` and may result in unexpected
48+
behavior.
4649

4750
* - :ref:`timeoutSecs <shutdownServer-method-timeoutSecs>`
4851

4952
- .. _shutdownServer-method-timeoutSecs:
5053

51-
Optional. The number of seconds the :term:`primary` should
52-
wait for a secondary to catch up. Defaults to ``10``.
54+
Optional.
55+
56+
.. _shutdownServer-method-quiesce-period:
57+
58+
.. |force| replace:: :ref:`force <shutdownServer-method-force>`
59+
.. |timeout| replace:: :ref:`timeoutSecs <shutdownServer-method-timeoutSecs>`
5360

54-
If no secondaries catch up within the specified time, the
55-
command fails.
61+
.. include:: /includes/quiesce-period.rst
62+
63+
In MongoDB 4.4 and earlier, for a :binary:`~bin.mongod`
64+
:term:`primary`, :ref:`timeoutSecs
65+
<shutdownServer-method-timeoutSecs>` is the number of seconds
66+
the :term:`primary` should wait for a secondary to catch up.
67+
If no secondaries catch up within the specified time, the
68+
command fails. Defaults to ``10`` seconds.
5669

5770
This operation provides a wrapper around the :dbcommand:`shutdown`
5871
command.
@@ -81,23 +94,25 @@ set member is running certain operations such as :ref:`index builds
8194
<shutdownServer-method-force>` to force the member to interrupt those
8295
operations and shut down.
8396

84-
Shutting Down the Replica Set Primary
85-
`````````````````````````````````````
97+
Shutting Down the Replica Set Primary, Secondary, or ``mongos``
98+
```````````````````````````````````````````````````````````````
99+
100+
.. include:: /includes/quiesce-period.rst
86101

87-
If running :method:`db.shutdownServer()` against the replica set
88-
:term:`primary`, the operation implicitly uses
102+
In MongoDB 4.4 and earlier, if running :method:`db.shutdownServer()`
103+
against the replica set :term:`primary`, the operation implicitly uses
89104
:dbcommand:`replSetStepDown` to step down the primary before shutting
90105
down the :binary:`~bin.mongod`. If no secondary in the replica set can
91106
catch up to the primary within ``10`` seconds, the shutdown operation
92-
fails. You can issue :method:`~db.shutdownServer()` with
93-
:ref:`force: true <shutdownServer-method-force>` to shut down the
94-
primary *even if* the step down fails.
107+
fails. You can issue :method:`db.shutdownServer()` with :ref:`force:
108+
true <shutdownServer-method-force>` to shut down the primary *even if*
109+
the step down fails.
95110

96111
.. warning::
97112

98113
Force shutdown of the primary can result in the
99114
:ref:`rollback <replica-set-rollback>` of any writes not
100-
yet replicated to a secondary.
115+
yet replicated to a secondary.
101116

102117
.. _method-shutdown-access-control:
103118

source/reference/parameters.txt

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2733,6 +2733,35 @@ Sharding Parameters
27332733

27342734
- :parameter:`maxTimeMSForHedgedReads`
27352735

2736+
.. parameter:: shutdownTimeoutMillisForSignaledShutdown
2737+
2738+
.. versionadded:: 5.0
2739+
2740+
*Type*: integer
2741+
2742+
*Default*: 15000
2743+
2744+
|mongod-only|
2745+
2746+
Specifies the time (in milliseconds) to wait for any ongoing database
2747+
operations to complete before initiating a shutdown of
2748+
:binary:`~bin.mongod` in response to a ``SIGTERM`` signal.
2749+
2750+
For example, to set the time to 250 milliseconds, you can issue the
2751+
following during startup:
2752+
2753+
.. code-block:: sh
2754+
2755+
mongod --setParameter shutdownTimeoutMillisForSignaledShutdown=250
2756+
2757+
Or if using the :dbcommand:`setParameter` command in a
2758+
:binary:`~bin.mongo` shell connected to a running
2759+
:binary:`~bin.mongod`:
2760+
2761+
.. code-block:: javascript
2762+
2763+
db.adminCommand( { setParameter: 1, shutdownTimeoutMillisForSignaledShutdown: 250 } )
2764+
27362765
.. parameter:: mongosShutdownTimeoutMillisForSignaledShutdown
27372766

27382767
.. versionadded:: 5.0
@@ -2745,7 +2774,7 @@ Sharding Parameters
27452774

27462775
Specifies the time (in milliseconds) to wait for any ongoing database
27472776
operations to complete before initiating a shutdown of
2748-
:binary:`~bin.mongos`.
2777+
:binary:`~bin.mongos` in response to a ``SIGTERM`` signal.
27492778

27502779
For example, to set the time to 250 milliseconds, you can issue the
27512780
following during startup:

source/release-notes/5.0.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ Removed Commands
124124
Replica Sets
125125
------------
126126

127+
Quiesce Period
128+
~~~~~~~~~~~~~~
129+
130+
Starting in MongoDB 5.0, :binary:`~bin.mongod` and :binary:`~bin.mongos`
131+
enter a :ref:`quiesce period <shutdown-cmd-quiesce-period>` to allow any
132+
ongoing database operations to complete before shutting down.
133+
127134
Limit Removed for ``members[n]._id`` Values
128135
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
129136

0 commit comments

Comments
 (0)