Skip to content

Commit b958e33

Browse files
kennethdyerKenneth P. J. Dyerajhuh-mdb
authored
DOCSP33213 fsync/fsyncUnlock - Backport to v4.4 (#5060)
* DOCSP-33213 fsync/fsyncUnlock Changes (#4802) * DOCSP-33213 Updates to fsync/fsyncUnlock for Self-Managed Backups of Sharded Clusters * Adds 7.1 versionadded * Reworks Larger Deployment notes * Documents new feature on fsyncUnlock and mongosh helpers * Fixes build issue * Adds lock timeout * Minor edits for cluster coverage * Minor edits for cluster coverage * Adds include for lock/unlock * Adjusts fsync text * Fixes tables * Adds notice for lock/unlock * Minor edit * Major edits to db.fsyncLock to bring it in sync * Minor edit * fsyncUnlock method edits * Minor edits * Minor edits * Adds release note * Fixes build issue * Fixes build issue * Fixes build issue * Fixes build issue * Fixes build issue * Fixes per Ali Co-authored-by: Alison Huh <[email protected]> * Fixes per Ali * Fixes per Ali Co-authored-by: Alison Huh <[email protected]> * Fixes per Nandini * Fixes per Nandini * Fixes per Nandini * Fixes per Nandini * Fixes per Nandini --------- Co-authored-by: Kenneth P. J. Dyer <[email protected]> Co-authored-by: Alison Huh <[email protected]> * fixes build issue * Fixes per Jeff --------- Co-authored-by: Kenneth P. J. Dyer <[email protected]> Co-authored-by: Alison Huh <[email protected]>
1 parent 01a362c commit b958e33

File tree

8 files changed

+184
-157
lines changed

8 files changed

+184
-157
lines changed

source/core/backups.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _backup-methods:
2+
13
======================
24
MongoDB Backup Methods
35
======================
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. important::
2+
3+
Servers maintain an fsync lock count. The :dbcommand:`fsync` command with
4+
the ``lock`` field set to ``true`` increments the lock count while the
5+
:dbcommand:`fsyncUnlock` command decrements it. To enable writes on a locked
6+
server or cluster, call the :dbcommand:`fsyncUnlock` command until the lock
7+
count reaches zero.
8+

source/includes/fsync-lock-method.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
Servers maintain an fsync lock count. The :method:`~db.fsyncLock` method
3+
increments the lock count while the :method:`~db.fsyncUnlock` method decrements
4+
it. To unlock writes on a server or cluster, call the :method:`~db.fsyncUnlock`
5+
method until the lock count reaches zero.
6+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
Starting in MongoDB 4.4.25, the :dbcommand:`fsync` and :dbcommand:`fsyncUnlock`
3+
commands can perform fsync operations sharded clusters.
4+
5+
When run on :program:`mongos` with the ``lock`` field set to ``true``, the
6+
:dbcommand:`fsync` command flushes writes from the storage layer to disk and
7+
locks each shard, preventing additional writes. The :dbcommand:`fsyncUnlock`
8+
command can then be used to unlock the cluster.
9+
10+
This feature enables self-managed backups of sharded clusters using
11+
:program:`mongodump`.
12+
13+

source/reference/command/fsync.txt

Lines changed: 100 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -19,70 +19,81 @@ Definition
1919

2020
.. dbcommand:: fsync
2121

22-
Forces the :binary:`~bin.mongod` process to flush all pending writes
23-
from the storage layer to disk and locks the *entire*
24-
:binary:`~bin.mongod` instance to prevent additional writes until the
25-
user releases the lock with a corresponding
26-
:dbcommand:`fsyncUnlock`. Optionally, you can use :dbcommand:`fsync`
27-
to lock the :binary:`~bin.mongod` instance and block write operations
28-
for the purpose of capturing backups.
29-
30-
As applications write data, MongoDB records the data in the storage
31-
layer and then writes the data to disk within the :setting:`~storage.syncPeriodSecs`
32-
interval, which is 60 seconds by default. Run :dbcommand:`fsync` when
33-
you want to flush writes to disk ahead of that interval.
22+
Flushes all pending writes from the storage layer to disk. When the ``lock``
23+
field is set to ``true``, it sets a lock on the server or cluster to prevent
24+
additional writes until the lock is released.
3425

3526

27+
.. versionadded:: 4.4.25
28+
29+
When the ``fsync`` command runs on :program:`mongos`, it performs the
30+
fsync operation on each shard in the cluster.
31+
32+
33+
As applications write data, MongoDB records the data in the storage layer
34+
and then writes the data to disk within the
35+
:setting:`~storage.syncPeriodSecs` interval, which is 60 seconds by default.
36+
Run ``fsync`` when you want to flush writes to disk ahead of that interval.
37+
38+
.. include:: /includes/fsync-lock-command
39+
40+
Use this command to block writes when you want to perform backup
41+
operations.
42+
43+
.. |method| replace:: :method:`db.fsyncLock` helper method
44+
.. include:: /includes/fact-dbcommand-tip
45+
46+
3647
The :dbcommand:`fsync` command has the following syntax:
3748

3849
.. code-block:: javascript
3950

40-
{ fsync: 1, lock: <Boolean>, comment: <any> }
51+
db.adminCommand(
52+
{
53+
fsync: 1,
54+
lock: <Boolean>,
55+
fsyncLockAcquisitionTimeout: <integer>,
56+
comment: <any>
57+
}
58+
)
4159

4260
The :dbcommand:`fsync` command has the following fields:
4361

4462

4563
.. list-table::
4664
:header-rows: 1
47-
:widths: 20 20 80
48-
65+
:widths: 20 20 60
66+
4967
* - Field
50-
5168
- Type
52-
5369
- Description
54-
70+
5571
* - ``fsync``
72+
- integer
73+
- Enter "1" to apply :dbcommand:`fsync`.
5674

75+
* - ``fsyncLockAcquisitionTimeoutMillis``
5776
- integer
77+
- Optional. Specifies the amount of time in milliseconds to wait to
78+
acquire locks. If the lock acquisition operation times out, the
79+
command returns a failed response.
5880

59-
- Enter "1" to apply :dbcommand:`fsync`.
60-
61-
* - ``lock``
81+
Default: ``90000``
6282

63-
- boolean
83+
.. versionadded:: 4.4.25
6484

65-
- Optional. Takes a lock on the :binary:`~bin.mongod` instance and blocks all
66-
write operations. Each :dbcommand:`fsync` with ``lock`` operation
85+
* - ``lock``
86+
- boolean
87+
- Optional. Takes a lock on the server or cluster and blocks all
88+
write operations. Each ``fsync`` with ``lock`` operation
6789
takes a lock.
6890

69-
7091
* - ``comment``
71-
7292
- any
73-
7493
- .. include:: /includes/extracts/comment-content.rst
7594

7695
.. versionadded:: 4.4
77-
78-
79-
To run the :dbcommand:`fsync` command, use the
80-
:method:`db.adminCommand()` method:
81-
82-
.. code-block:: javascript
83-
84-
db.adminCommand( { fsync: 1, ... } )
85-
96+
8697
Considerations
8798
--------------
8899

@@ -91,61 +102,60 @@ Considerations
91102
Impact on Larger Deployments
92103
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93104

94-
An :dbcommand:`fsync` lock is only possible on *individual*
95-
:binary:`~bin.mongod` instances of a
96-
sharded cluster, not on the entire cluster. To back up an entire sharded
97-
cluster, please see :doc:`/administration/backup-sharded-clusters` for
98-
more information.
105+
.. versionadded:: 4.4.25
99106

100-
Alternatives with Journaling
101-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107+
When the ``fsync`` command runs on :program:`mongos`, it performs the fsync
108+
operation on the entire cluster. By setting the ``lock`` field to ``true``,
109+
it sets a lock on the cluster, preventing additional writes.
102110

103-
If your :binary:`~bin.mongod` has :term:`journaling <journal>` enabled,
104-
please use :ref:`file system or volume/block level snapshot tool <backup-with-journaling>` to create a
105-
backup of the data set and the journal together as a single unit.
111+
To take a usable self-managed backup, before locking a sharded cluster:
106112

113+
- Ensure that no chunk migration, resharding, or DDL operations are active.
107114

108-
``fsync`` with ``lock: true``
109-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
115+
- Stop the balancer to prevent additional chunk migrations from starting.
110116

111-
.. versionchanged:: 3.4
117+
Alternatives with Journaling
118+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
112119

113-
The ``{ fsync: 1, lock: true }`` command now returns a ``lockCount``
114-
in the return document.
120+
If your :program:`mongod` has :term:`journaling <journal>` enabled, use
121+
:ref:`a file system or volume/block level snapshot tool <backup-with-journaling>`
122+
to create a backup of the data set and the journal together as a single unit.
115123

116-
After ``{ fsync: 1, lock: true }`` runs on a :binary:`~bin.mongod`, all
117-
write operations will block. The :binary:`~bin.mongo` shell provides a
118-
helper method :method:`db.fsyncLock()`.
119124

125+
Lock Count
126+
~~~~~~~~~~
120127

121-
.. note::
128+
The ``fsync`` command returns a document includes a ``lockCount`` field. When
129+
run on :program:`mongod`, the count indicates the number of fsync locks set on
130+
the server.
122131

123-
The ``{ fsync: 1, lock: true }`` operation maintain a lock count.
124-
Each ``{ fsync: 1, lock: true }`` operation increments the lock
125-
count.
132+
When run on a sharded cluster, :program:`mongos` sends the fsync operation to
133+
each shard and returns the results, which includes the ``lockCount`` for each.
126134

127-
To unlock a :binary:`~bin.mongod` instance for writes, the lock count
128-
must be zero. That is, for a given number of ``{ fsync: 1, lock:
129-
true }`` operation, you must issue a corresponding number of unlock
130-
operations in order to unlock the instance for writes. To unlock,
131-
see :method:`db.fsyncUnlock()`.
135+
.. note::
136+
137+
If the ``lockCount`` field is non-zero, all writes are blocked on the server
138+
and cluster. To reduce the lock count, use the :dbcommand:`fsyncUnlock`
139+
command.
132140

133141
Examples
134142
--------
135143

136-
Lock ``mongod`` Instance
137-
~~~~~~~~~~~~~~~~~~~~~~~~
144+
Fsync Lock
145+
~~~~~~~~~~
138146

139147
.. note::
140148

141149
.. include:: /includes/extracts/wt-fsync-lock-compatibility-command.rst
142150

143-
The primary use of :dbcommand:`fsync` is to lock the :binary:`~bin.mongod`
144-
instance in order to back up the files within :binary:`~bin.mongod`\ 's :setting:`~storage.dbPath`.
145-
The operation flushes all data to the storage layer and
146-
blocks all write operations until you unlock the :binary:`~bin.mongod` instance.
151+
The ``fsync`` command can lock an individual :program:`mongod` instance or a
152+
sharded cluster through :program:`mongos`. When run with the ``lock`` field
153+
set to ``true``, the fsync operation flushes all data to the storage layer and
154+
blocks all additional write operations until you unlock the instance or
155+
cluster.
147156

148-
To lock the database, use the ``lock`` field set to ``true``:
157+
To lock the database, use the ``fsync`` command to set the ``lock`` field
158+
to ``true``:
149159

150160
.. code-block:: javascript
151161

@@ -163,37 +173,38 @@ operation and the ``lockCount``:
163173
"ok" : 1
164174
}
165175

166-
You may continue to perform read operations on a :binary:`~bin.mongod` instance that has a
167-
:dbcommand:`fsync` lock. However, after the first write operation all
168-
subsequent read operations wait until you unlock the :binary:`~bin.mongod` instance.
176+
When locked, write operations are blocked. Separate connections may continue
177+
read operations until the first attempt at a write operation, then they also
178+
wait until the sever or cluster is unlocked.
179+
169180

170181
.. important::
171182

172-
The ``{ fsync: 1, lock: true }`` operation maintain a lock count.
183+
The fsync lock operation maintains a lock count.
173184

174-
To unlock a :binary:`~bin.mongod` instance for writes, the lock count
175-
must be zero. That is, for a given number of ``{ fsync: 1, lock:
176-
true }`` operation, you must issue a corresponding number of unlock
177-
operations in order to unlock the instance for writes.
185+
To unlock a server or cluster for writes, the lock count
186+
must be zero. That is, for the given number of times you perform an fsync
187+
lock, you must issue a corresponding number of unlock operations to unlock
188+
the server or cluster for writes.
178189

179-
Unlock ``mongod`` Instance
180-
~~~~~~~~~~~~~~~~~~~~~~~~~~
190+
Fsync Unlock
191+
~~~~~~~~~~~~
181192

182-
To unlock the :binary:`~bin.mongod`, use :method:`db.fsyncUnlock()`:
193+
To unlock a server of cluster, use the :dbcommand:`fsyncUnlock` command:
183194

184195
.. code-block:: javascript
185196

186-
db.fsyncUnlock();
197+
db.adminCommnad( { fsyncUnlock: 1 } )
187198

188-
Repeat the :method:`db.fsyncUnlock()` to reduce the lock count to zero
189-
to unlock the instance for writes.
199+
Repeat this command as many times as needed to reduce the lock count to zero.
200+
Once the lock count reaches zero, the server or cluster can resume writes.
190201

191202
Check Lock Status
192203
~~~~~~~~~~~~~~~~~
193204

194205
To check the state of the fsync lock, use :method:`db.currentOp()`. Use
195-
the following JavaScript function in the shell to test if :binary:`~bin.mongod` instance is
196-
currently locked:
206+
the following JavaScript function in the shell to test if the server or
207+
cluster is currently locked:
197208

198209
.. code-block:: javascript
199210

@@ -212,5 +223,6 @@ call it, with the following syntax:
212223

213224
serverIsLocked()
214225

215-
This function will return ``true`` if the :binary:`~bin.mongod` instance is
216-
currently locked and ``false`` if the :binary:`~bin.mongod` is not locked.
226+
This function will return ``true`` if the server or cluster is
227+
currently locked and ``false`` if the server or cluster is not locked.
228+

source/reference/command/fsyncUnlock.txt

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,30 @@ Definition
1919

2020
.. dbcommand:: fsyncUnlock
2121

22-
Reduces the lock taken by :dbcommand:`fsync` (with the lock option)
23-
on a :binary:`~bin.mongod` instance by 1.
22+
Reduces the lock count on the server or cluster. To enable write operations,
23+
the lock count must be zero.
24+
2425

25-
.. important::
26+
.. versionadded:: 4.4.25
2627

27-
The :dbcommand:`fsync` ``lock`` and :dbcommand:`fsyncUnlock`
28-
operations maintain a lock count. Each :dbcommand:`fsync` ``lock``
29-
operation increments the lock count, and :dbcommand:`fsyncUnlock`
30-
decrements the lock count.
28+
When the ``fsyncUnlock`` command runs on :program:`mongos`, it
29+
reduces the lock count for each shard in the cluster.
3130

32-
To unlock a :binary:`~bin.mongod` instance for writes, the lock count
33-
must be zero. That is, for a given number of :dbcommand:`fsync`
34-
``lock`` operations, you must issue a corresponding number of
35-
:dbcommand:`fsyncUnlock` operations to unlock the instance for
36-
writes.
31+
Use this command to unblock writes after you finish a backup operation.
32+
33+
.. include:: /includes/fsync-lock-command
3734

3835
:dbcommand:`fsyncUnlock` is an administrative operation. Typically
3936
you will use :dbcommand:`fsyncUnlock` following a database
4037
:doc:`backup operation </core/backups>`.
4138

39+
.. |method| replace:: :method:`db.fsyncUnlock` helper method
40+
.. include:: /includes/fact-dbcommand-tip
41+
4242
To run the :dbcommand:`fsyncUnlock` command, use the
4343
:method:`db.adminCommand()` method:
4444

45+
4546
.. code-block:: javascript
4647

4748
db.adminCommand( { fsyncUnlock: 1, comment: <any> } )
@@ -54,25 +55,19 @@ Definition
5455
.. list-table::
5556
:header-rows: 1
5657
:widths: 30 70
57-
58+
5859
* - Field
59-
6060
- Description
61-
61+
6262
* - ``info``
6363
- Information on the status of the operation
64-
64+
6565
* - ``lockCount`` (*New in version 3.4*)
6666
- The number of locks remaining on the instance after the operation.
67-
67+
6868
* - ``ok``
6969
- The status code.
70-
71-
.. tip::
72-
73-
The :binary:`~bin.mongo` shell provides the helper method
74-
:method:`db.fsyncUnlock()`.
75-
70+
7671
Examples
7772
--------
7873

0 commit comments

Comments
 (0)