10
10
:depth: 1
11
11
:class: singlecol
12
12
13
+ .. meta::
14
+ :description: fsync, fsynclock, fsync lock, lock
15
+ :keywords: fsync, fsynclock, fsync lock, lock
16
+
13
17
Definition
14
18
----------
15
19
@@ -24,6 +28,7 @@ Definition
24
28
layer and then writes the data to disk within the :setting:`~storage.syncPeriodSecs`
25
29
interval, which is 60 seconds by default. Run :dbcommand:`fsync` when
26
30
you want to flush writes to disk ahead of that interval.
31
+
27
32
28
33
The :dbcommand:`fsync` command has the following syntax:
29
34
@@ -35,6 +40,15 @@ Definition
35
40
36
41
.. include:: /includes/apiargs/dbcommand-fsync-field.rst
37
42
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
+
38
52
Considerations
39
53
--------------
40
54
@@ -59,28 +73,30 @@ If your :binary:`~bin.mongod` has :term:`journaling <journal>` enabled,
59
73
please use :ref:`file system or volume/block level snapshot tool <backup-with-journaling>` to create a
60
74
backup of the data set and the journal together as a single unit.
61
75
62
- Impact on Read Operations
63
- ~~~~~~~~~~~~~~~~~~~~~~~~~
64
76
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
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70
79
71
- .. important::
80
+ .. versionchanged:: 3.4
81
+
82
+ The ``{ fsync: 1, lock: true }`` command now returns a ``lockCount``
83
+ in the return document.
72
84
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.
76
87
77
- .. warning::
78
88
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.
82
94
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()`.
84
100
85
101
Examples
86
102
--------
@@ -94,7 +110,7 @@ The :dbcommand:`fsync` operation is synchronous by default. To run
94
110
95
111
.. code-block:: javascript
96
112
97
- { fsync: 1, async: true }
113
+ db.adminCommand( { fsync: 1, async: true } )
98
114
99
115
The operation returns immediately. To view the status of the
100
116
:dbcommand:`fsync` operation, check the output of
@@ -116,12 +132,33 @@ To lock the database, use the ``lock`` field set to ``true``:
116
132
117
133
.. code-block:: javascript
118
134
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
+ }
120
148
121
149
You may continue to perform read operations on a :binary:`~bin.mongod` instance that has a
122
150
:dbcommand:`fsync` lock. However, after the first write operation all
123
151
subsequent read operations wait until you unlock the :binary:`~bin.mongod` instance.
124
152
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
+
125
162
Unlock ``mongod`` Instance
126
163
~~~~~~~~~~~~~~~~~~~~~~~~~~
127
164
@@ -131,6 +168,8 @@ To unlock the :binary:`~bin.mongod`, use :method:`db.fsyncUnlock()`:
131
168
132
169
db.fsyncUnlock();
133
170
171
+ Repeat the :method:`db.fsyncUnlock()` to reduce the lock count to zero
172
+ to unlock the instance for writes.
134
173
135
174
Check Lock Status
136
175
~~~~~~~~~~~~~~~~~
0 commit comments