1010 :depth: 1
1111 :class: singlecol
1212
13+ .. meta::
14+ :description: fsync, fsynclock, fsync lock, lock
15+ :keywords: fsync, fsynclock, fsync lock, lock
16+
1317Definition
1418----------
1519
@@ -24,6 +28,7 @@ Definition
2428 layer and then writes the data to disk within the :setting:`~storage.syncPeriodSecs`
2529 interval, which is 60 seconds by default. Run :dbcommand:`fsync` when
2630 you want to flush writes to disk ahead of that interval.
31+
2732
2833 The :dbcommand:`fsync` command has the following syntax:
2934
@@ -35,6 +40,15 @@ Definition
3540
3641 .. include:: /includes/apiargs/dbcommand-fsync-field.rst
3742
43+ To run the :dbcommand:`fsync` command, use the
44+ :method:`db.adminCommand()` method:
45+
46+ .. code-block:: javascript
47+
48+ db.adminCommand( { fsync: 1, ... } )
49+
50+
51+
3852Considerations
3953--------------
4054
@@ -59,28 +73,30 @@ If your :binary:`~bin.mongod` has :term:`journaling <journal>` enabled,
5973please use :ref:`file system or volume/block level snapshot tool <backup-with-journaling>` to create a
6074backup of the data set and the journal together as a single unit.
6175
62- Impact on Read Operations
63- ~~~~~~~~~~~~~~~~~~~~~~~~~
6476
65- After :dbcommand:`fsync` with the ``lock`` option runs on a
66- :binary:`~bin.mongod`, all write operations will block until a subsequent
67- unlock. Read operations *may* also block. As a result, :dbcommand:`fsync`
68- with lock is not a reliable mechanism for making a :binary:`~bin.mongod`
69- instance operate in a read-only mode.
77+ ``fsync`` with ``lock: true``
78+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7079
71- .. important::
80+ .. versionchanged:: 3.4
81+
82+ The ``{ fsync: 1, lock: true }`` command now returns a ``lockCount``
83+ in the return document.
7284
73- Blocked read operations prevent verification of authentication.
74- Such reads are necessary to establish new connections
75- to a :binary:`~bin.mongod` that enforces authorization checks.
85+ After ``{ fsync: 1, lock: true }`` runs on a :binary:`~bin.mongod`, all
86+ write operations will block.
7687
77- .. warning::
7888
79- When calling :dbcommand:`fsync` with the ``lock`` option, ensure that
80- the connection remains open to allow a subsequent call to
81- :method:`db.fsyncUnlock()`.
89+ .. note::
90+
91+ The ``{ fsync: 1, lock: true }`` operation maintain a lock count.
92+ Each ``{ fsync: 1, lock: true }`` operation increments the lock
93+ count.
8294
83- Closing the connection may make it difficult to release the lock.
95+ To unlock a :binary:`~bin.mongod` instance for writes, the lock count
96+ must be zero. That is, for a given number of ``{ fsync: 1, lock:
97+ true }`` operation, you must issue a corresponding number of unlock
98+ operations in order to unlock the instance for writes. To unlock,
99+ see :method:`db.fsyncUnlock()`.
84100
85101Examples
86102--------
@@ -94,7 +110,7 @@ The :dbcommand:`fsync` operation is synchronous by default. To run
94110
95111.. code-block:: javascript
96112
97- { fsync: 1, async: true }
113+ db.adminCommand( { fsync: 1, async: true } )
98114
99115The operation returns immediately. To view the status of the
100116:dbcommand:`fsync` operation, check the output of
@@ -116,12 +132,33 @@ To lock the database, use the ``lock`` field set to ``true``:
116132
117133.. code-block:: javascript
118134
119- { fsync: 1, lock: true }
135+ db.adminCommand( { fsync: 1, lock: true } )
136+
137+ The operation returns a document that includes the status of the
138+ operation and the ``lockCount``:
139+
140+ .. code-block:: javascript
141+
142+ {
143+ "info" : "now locked against writes, use db.fsyncUnlock() to unlock",
144+ "lockCount" : NumberLong(1),
145+ "seeAlso" : "http://dochub.mongodb.org/core/fsynccommand",
146+ "ok" : 1
147+ }
120148
121149You may continue to perform read operations on a :binary:`~bin.mongod` instance that has a
122150:dbcommand:`fsync` lock. However, after the first write operation all
123151subsequent read operations wait until you unlock the :binary:`~bin.mongod` instance.
124152
153+ .. important::
154+
155+ The ``{ fsync: 1, lock: true }`` operation maintain a lock count.
156+
157+ To unlock a :binary:`~bin.mongod` instance for writes, the lock count
158+ must be zero. That is, for a given number of ``{ fsync: 1, lock:
159+ true }`` operation, you must issue a corresponding number of unlock
160+ operations in order to unlock the instance for writes.
161+
125162Unlock ``mongod`` Instance
126163~~~~~~~~~~~~~~~~~~~~~~~~~~
127164
@@ -131,6 +168,8 @@ To unlock the :binary:`~bin.mongod`, use :method:`db.fsyncUnlock()`:
131168
132169 db.fsyncUnlock();
133170
171+ Repeat the :method:`db.fsyncUnlock()` to reduce the lock count to zero
172+ to unlock the instance for writes.
134173
135174Check Lock Status
136175~~~~~~~~~~~~~~~~~
0 commit comments