Skip to content

Commit de4e26d

Browse files
committed
DOCS-9265, DOCS-5976: fsyncLock/Unlock and lock counts
1 parent 328e64e commit de4e26d

9 files changed

+316
-74
lines changed

source/includes/apiargs-dbcommand-fsync-field.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ type: boolean
2121
---
2222
arg_name: field
2323
description: |
24-
Locks :binary:`~bin.mongod` instance and blocks all write operations.
24+
25+
Takes a lock on the :binary:`~bin.mongod` instance and blocks all
26+
write operations. Each :dbcommand:`fsync` with ``lock`` operation
27+
takes a lock.
28+
2529
interface: dbcommand
2630
name: lock
2731
operation: fsync

source/includes/ref-toc-command-administration.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ name: ":dbcommand:`fsync`"
6666
file: /reference/command/fsync
6767
description: "Flushes pending writes to the storage layer and locks the database to allow backups."
6868
---
69+
name: ":dbcommand:`fsyncUnlock`"
70+
file: /reference/command/fsyncUnlock
71+
description: "Unlocks one fsync lock."
72+
---
6973
name: ":dbcommand:`getParameter`"
7074
file: /reference/command/getParameter
7175
description: "Retrieves configuration options."

source/includes/steps-backup-sharded-cluster-with-snapshots.yaml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ action:
4545
language: javascript
4646
code: |
4747
db.fsyncLock()
48-
post: |
49-
When calling :method:`db.fsyncLock()`, ensure that the connection
50-
is kept open to allow a subsequent call to
51-
:method:`db.fsyncUnlock()`.
48+
5249
- heading: Lock config server replica set secondary.
5350
pre: |
5451
If locking a secondary of the CSRS, confirm that the member has
@@ -98,9 +95,6 @@ action:
9895
language: javascript
9996
code: |
10097
db.fsyncLock()
101-
post: |
102-
When calling :method:`db.fsyncLock()`, ensure that the connection is
103-
kept open to allow a subsequent call to :method:`db.fsyncUnlock()`.
10498
---
10599
title: Back up one of the config servers.
106100
stepnum: 3
@@ -136,8 +130,7 @@ pre: |
136130
unlock them.
137131
138132
To unlock the replica set members, use :method:`db.fsyncUnlock()`
139-
method in the :binary:`~bin.mongo` shell. For each locked member, use the
140-
same :binary:`~bin.mongo` shell used to lock the instance.
133+
method in the :binary:`~bin.mongo` shell.
141134
action:
142135
language: javascript
143136
code: |

source/includes/steps-backup-sharded-clusters-dumps.yaml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ action:
3939
language: javascript
4040
code: |
4141
db.fsyncLock()
42-
post: |
43-
When calling :method:`db.fsyncLock()`, ensure that the connection
44-
is kept open to allow a subsequent call to
45-
:method:`db.fsyncUnlock()`.
42+
4643
- heading: Lock config server replica set secondary.
4744
pre: |
4845
If locking a secondary of the CSRS, confirm that the member has
@@ -92,9 +89,7 @@ action:
9289
language: javascript
9390
code: |
9491
db.fsyncLock()
95-
post: |
96-
When calling :method:`db.fsyncLock()`, ensure that the connection is
97-
kept open to allow a subsequent call to :method:`db.fsyncUnlock()`.
92+
9893
---
9994
title: Backup one config server.
10095
stepnum: 3
@@ -116,7 +111,7 @@ action:
116111
If your deployment uses CSRS config servers, unlock the config server
117112
node before proceeding to the next step.
118113
To unlock the CSRS member, use :method:`db.fsyncUnlock()` method in
119-
the :binary:`~bin.mongo` shell used to lock the instance.
114+
the :binary:`~bin.mongo` shell.
120115
language: javascript
121116
code: |
122117
db.fsyncUnlock()
@@ -139,8 +134,7 @@ stepnum: 5
139134
ref: restart-replica-set-members
140135
pre: |
141136
To unlock the replica set members, use :method:`db.fsyncUnlock()`
142-
method in the :binary:`~bin.mongo` shell. For each locked member, use the
143-
same :binary:`~bin.mongo` shell used to lock the instance.
137+
method in the :binary:`~bin.mongo` shell.
144138
action:
145139
language: javascript
146140
code: |

source/reference/command/fsync.txt

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ fsync
1010
:depth: 1
1111
:class: singlecol
1212

13+
.. meta::
14+
:description: fsync, fsynclock, fsync lock, lock
15+
:keywords: fsync, fsynclock, fsync lock, lock
16+
1317
Definition
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+
3852
Considerations
3953
--------------
4054

@@ -59,28 +73,30 @@ If your :binary:`~bin.mongod` has :term:`journaling <journal>` enabled,
5973
please use :ref:`file system or volume/block level snapshot tool <backup-with-journaling>` to create a
6074
backup 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

85101
Examples
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

99115
The 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

121149
You 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
123151
subsequent 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+
125162
Unlock ``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

135174
Check Lock Status
136175
~~~~~~~~~~~~~~~~~
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
===========
2+
fsyncUnlock
3+
===========
4+
5+
.. default-domain:: mongodb
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 1
11+
:class: singlecol
12+
13+
.. meta::
14+
:description: fsync, fsyncUnlock, fsync unlock, unlock
15+
:keywords: fsync, fsyncUnlock, fsync unlock, unlock
16+
17+
Definition
18+
----------
19+
20+
.. dbcommand:: fsyncUnlock
21+
22+
Reduces the lock taken by :dbcommand:`fsync` (with the lock option)
23+
on a :binary:`~bin.mongod` instance by 1.
24+
25+
.. important::
26+
27+
The :dbcommand:`fsync` lock and :dbcommand:`fsyncUnlock`
28+
operations maintain a lock count. Each :dbcommand:`fsync` lock
29+
opeartion increments the lock count, and :dbcommand:`fsyncUnlock`
30+
decrements the lock count.
31+
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.
37+
38+
:dbcommand:`fsyncUnlock` is an administrative operation. Typically
39+
you will use :dbcommand:`fsyncUnlock` following a database
40+
:doc:`backup operation </core/backups>`.
41+
42+
To run the :dbcommand:`fsyncUnlock` command, use the
43+
:method:`db.adminCommand()` method:
44+
45+
.. code-block:: javascript
46+
47+
db.adminCommand( { fsyncUnlock: 1 } )
48+
49+
The operation returns a document with the following fields:
50+
51+
.. list-table::
52+
53+
* - ``info``
54+
- information on the status of the operation
55+
56+
* - ``lockCount``
57+
- The number of locks remaining on the instance after the operation.
58+
59+
.. versionadded:: 3.4
60+
61+
* - ``ok``
62+
- The status code.
63+
64+
.. tip::
65+
66+
The :binary:`~bin.mongo` shell provides the helper method
67+
:method:`db.fsyncUnlock()`.
68+
69+
Examples
70+
--------
71+
72+
Consider a situation where :method:`db.fsyncLock()` has been issued two
73+
times. The following :dbcommand:`fsyncUnlock` operation reduces the
74+
locks taken by :method:`db.fsyncLock()` by 1:
75+
76+
.. code-block:: javascript
77+
78+
db.adminCommand( { fsyncUnlock: 1 } )
79+
80+
The operation returns the following document:
81+
82+
.. code-block:: javascript
83+
84+
{ "info" : "fsyncUnlock completed", "lockCount" : NumberLong(1), "ok" : 1 }
85+
86+
As the ``lockCount`` is greater than 0, the :binary:`~bin.mongod` instance
87+
is locked against writes. To unlock the instance for writes, run the
88+
unlock operation again:
89+
90+
.. code-block:: javascript
91+
92+
db.adminCommand( { fsyncUnlock: 1 } )
93+
94+
The operation returns the following document:
95+
96+
.. code-block:: javascript
97+
98+
{ "info" : "fsyncUnlock completed", "lockCount" : NumberLong(0), "ok" : 1 }
99+
100+
The :binary:`~bin.mongod` instance is unlocked for writes.

0 commit comments

Comments
 (0)