@@ -19,18 +19,30 @@ Definition
19
19
20
20
.. dbcommand:: fsync
21
21
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.
25
+
26
+
27
+ .. versionadded:: 6.0.11
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
+
34
46
35
47
Syntax
36
48
------
@@ -39,10 +51,11 @@ The command has the following syntax:
39
51
40
52
.. code-block:: javascript
41
53
42
- db.runCommand (
54
+ db.adminCommand (
43
55
{
44
56
fsync: 1,
45
57
lock: <Boolean>,
58
+ fsyncLockAcquisitionTimeout: <integer>,
46
59
comment: <any>
47
60
}
48
61
)
@@ -54,7 +67,7 @@ The command has the following fields:
54
67
55
68
.. list-table::
56
69
:header-rows: 1
57
- :widths: 20 20 80
70
+ :widths: 20 20 60
58
71
59
72
* - Field
60
73
- Type
@@ -63,11 +76,21 @@ The command has the following fields:
63
76
* - ``fsync``
64
77
- integer
65
78
- Enter "1" to apply :dbcommand:`fsync`.
66
-
79
+
80
+ * - ``fsyncLockAcquisitionTimeoutMillis``
81
+ - integer
82
+ - Optional. Specifies the amount of time in milliseconds to wait to
83
+ acquire locks. If the lock acquisition operation times out, the
84
+ command returns a failed response.
85
+
86
+ Default: ``90000``
87
+
88
+ .. versionadded:: 6.0.11
89
+
67
90
* - ``lock``
68
91
- boolean
69
- - Optional. Takes a lock on the :binary:`~bin.mongod` instance and blocks all
70
- write operations. Each :dbcommand:` fsync` with ``lock`` operation
92
+ - Optional. Takes a lock on the server or cluster and blocks all
93
+ write operations. Each `` fsync` ` with ``lock`` operation
71
94
takes a lock.
72
95
73
96
* - ``comment``
@@ -76,13 +99,6 @@ The command has the following fields:
76
99
77
100
.. versionadded:: 4.4
78
101
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
-
86
102
Considerations
87
103
--------------
88
104
@@ -91,61 +107,61 @@ Considerations
91
107
Impact on Larger Deployments
92
108
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93
109
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.
110
+ .. versionadded:: 6.0.11
111
+
112
+ When the ``fsync`` command runs on :program:`mongos`, it performs the fsync
113
+ operation on the entire cluster. By setting the ``lock`` field to ``true``,
114
+ it sets a lock on the cluster, preventing additional writes.
115
+
116
+ To take a usable self-managed backup, before locking a sharded cluster:
117
+
118
+ - Ensure that no chunk migration, resharding, or DDL operations are active.
119
+
120
+ - Stop the balancer to prevent additional chunk migrations from starting.
99
121
100
122
Alternatives with Journaling
101
123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
102
124
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.
106
-
125
+ If your :program:`mongod` has :term:`journaling <journal>` enabled, use
126
+ :ref:`a file system or volume/block level snapshot tool <backup-with-journaling>`
127
+ to create a backup of the data set and the journal together as a single unit.
107
128
108
- ``fsync`` with ``lock: true``
109
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
110
129
111
- .. versionchanged:: 3.4
130
+ Lock Count
131
+ ~~~~~~~~~~
112
132
113
- The ``{ fsync: 1, lock: true }`` command now returns a ``lockCount``
114
- in the return document.
133
+ The ``fsync`` command returns a document includes a ``lockCount`` field. When
134
+ run on :program:`mongod`, the count indicates the number of fsync locks set on
135
+ the server.
115
136
116
- After ``{ fsync: 1, lock: true }`` runs on a :binary:`~bin.mongod`, all
117
- write operations will block. :binary:`~bin.mongosh` provides a
118
- helper method :method:`db.fsyncLock()`.
137
+ When run on a sharded cluster, :program:`mongos` sends the fsync operation to
138
+ each shard and returns the results, which includes the ``lockCount`` for each.
119
139
120
140
121
141
.. note::
122
142
123
- The ``{ fsync: 1, lock: true }`` operation maintain a lock count.
124
- Each ``{ fsync: 1, lock: true }`` operation increments the lock
125
- count.
126
-
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()`.
143
+ If the ``lockCount`` field is non-zero, all writes are blocked on the server
144
+ and cluster. To reduce the lock count, use the :dbcommand:`fsyncUnlock`
145
+ command.
132
146
133
147
Examples
134
148
--------
135
149
136
- Lock ``mongod`` Instance
137
- ~~~~~~~~~~~~~~~~~~~~~~~~
150
+ Fsync Lock
151
+ ~~~~~~~~~~
138
152
139
153
.. note::
140
154
141
155
.. include:: /includes/extracts/wt-fsync-lock-compatibility-command.rst
142
156
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.
157
+ The ``fsync`` command can lock an individual :program:`mongod` instance or a
158
+ sharded cluster through :program:`mongos`. When run with the ``lock`` field
159
+ set to ``true``, the fsync operation flushes all data to the storage layer and
160
+ blocks all additional write operations until you unlock the instance or
161
+ cluster.
147
162
148
- To lock the database, use the ``lock`` field set to ``true``:
163
+ To lock the database, use the ``fsync`` command to set the ``lock`` field
164
+ to ``true``:
149
165
150
166
.. code-block:: javascript
151
167
@@ -163,37 +179,38 @@ operation and the ``lockCount``:
163
179
"ok" : 1
164
180
}
165
181
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.
182
+ When locked, write operations are blocked. Separate connections may continue
183
+ read operations until the first attempt at a write operation, then they also
184
+ wait until the sever or cluster is unlocked.
185
+
169
186
170
187
.. important::
171
188
172
- The ``{ fsync: 1, lock: true }`` operation maintain a lock count.
189
+ The fsync lock operation maintains a lock count.
173
190
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.
191
+ To unlock a server or cluster for writes, the lock count
192
+ must be zero. That is, for the given number of times you perform an fsync
193
+ lock , you must issue a corresponding number of unlock operations to unlock
194
+ the server or cluster for writes.
178
195
179
- Unlock ``mongod`` Instance
180
- ~~~~~~~~~~~~~~~~~~~~~~~~~~
196
+ Fsync Unlock
197
+ ~~~~~~~~~~~~
181
198
182
- To unlock the :binary:`~bin.mongod` , use :method:`db. fsyncUnlock()` :
199
+ To unlock a server of cluster , use the :dbcommand:` fsyncUnlock` command :
183
200
184
201
.. code-block:: javascript
185
202
186
- db.fsyncUnlock();
203
+ db.adminCommnad( { fsyncUnlock: 1 } )
187
204
188
- Repeat the :method:`db.fsyncUnlock()` to reduce the lock count to zero
189
- to unlock the instance for writes.
205
+ Repeat this command as many times as needed to reduce the lock count to zero.
206
+ Once the lock count reaches zero, the server or cluster can resume writes.
190
207
191
208
Check Lock Status
192
209
~~~~~~~~~~~~~~~~~
193
210
194
211
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:
212
+ the following JavaScript function in the shell to test if the server or
213
+ cluster is currently locked:
197
214
198
215
.. code-block:: javascript
199
216
@@ -212,5 +229,6 @@ call it with the following syntax:
212
229
213
230
serverIsLocked()
214
231
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.
232
+ This function will return ``true`` if the server or cluster is
233
+ currently locked and ``false`` if the server or cluster is not locked.
234
+
0 commit comments