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