Skip to content

Commit e5a5444

Browse files
committedSep 2, 2021
(DOCSP-18316): Improve implicit default write concern docs
1 parent ff4907b commit e5a5444

File tree

5 files changed

+62
-30
lines changed

5 files changed

+62
-30
lines changed
 

‎source/core/replica-set-rollbacks.txt

+12-11
Original file line numberDiff line numberDiff line change
@@ -171,25 +171,26 @@ administrators can decide the next course of action to take.
171171
Avoid Replica Set Rollbacks
172172
---------------------------
173173

174-
For replica sets, the :doc:`write concern {w: 1}
175-
</reference/write-concern>` only provides acknowledgement of write
176-
operations on the primary. With the default write concern, data may be
177-
rolled back if the primary steps down before the write operations have
178-
replicated to any of the secondaries. This includes data written in
179-
:doc:`multi-document transactions </core/transactions>` that commit
180-
using :writeconcern:`"w: 1" <\<number\>>` write concern.
181-
182-
.. include:: /includes/5.0-default-wc.rst
174+
For replica sets, the :doc:`write concern </reference/write-concern>`
175+
:writeconcern:`{ w: 1 } <\<number\>>` only provides acknowledgement of write
176+
operations on the primary. Data may be rolled back if the primary steps
177+
down before the write operations have replicated to any of the
178+
secondaries. This includes data written in :doc:`multi-document
179+
transactions </core/transactions>` that commit using
180+
:writeconcern:`{ w: 1 } <\<number\>>` write concern.
183181

184182
Journaling and Write Concern ``majority``
185183
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
186184

187185
To prevent rollbacks of data that have been acknowledged to the client,
188-
run all voting members with journaling enabled and use :ref:`w:
189-
majority write concern <wc-w>` to guarantee that the write operations
186+
run all voting members with journaling enabled and use :ref:`{ w:
187+
"majority" } write concern <wc-w>` to guarantee that the write operations
190188
propagate to a majority of the replica set nodes before returning with
191189
acknowledgement to the issuing client.
192190

191+
Starting in MongoDB 5.0, ``{ w: "majority" }`` is the default write concern
192+
for *most* MongoDB deployments. See :ref:`wc-default-behavior`.
193+
193194
.. include:: /includes/extracts/no-journaling-rollback.rst
194195

195196
Visibility of Data That Can Be Rolled Back

‎source/includes/5.0-default-wc.rst

+44-6
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,57 @@ Starting in MongoDB 5.0, the implicit default write concern is
33
considerations are made for deployments containing :ref:`arbiters
44
<replica-set-arbiter-configuration>`:
55

6-
- If the number of data-bearing voting members is not strictly more
7-
than the voting majority, the default write concern is ``w: 1``.
6+
- The voting majority of a replica set is 1 plus half the number of
7+
voting members, rounded down. If the number of data-bearing voting
8+
members is not greater than the voting majority, the default write
9+
concern is ``{ w: 1 }``.
810

9-
- In all other scenarios, the default write concern is ``w:
10-
"majority"``.
11+
- In all other scenarios, the default write concern is ``{ w:
12+
"majority" }``.
1113

1214
Specifically, MongoDB uses the following formula to determine the
1315
default write concern:
1416

1517
.. code-block:: none
1618
:copyable: false
1719
18-
if [(#arbiters > 0) AND (#arbiters >= ½(#voting nodes) - 1)]
20+
if [ (#arbiters > 0) AND (#non-arbiters <= majority(#voting-nodes)) ]
1921
defaultWriteConcern = { w: 1 }
2022
else
21-
defaultWriteConcern = { w: majority }
23+
defaultWriteConcern = { w: "majority" }
24+
25+
For example, consider the following deployments and their respective
26+
default write concerns:
27+
28+
.. list-table::
29+
:header-rows: 1
30+
31+
* - Non-Arbiters
32+
- Arbiters
33+
- Voting Nodes
34+
- Majority of Voting Nodes
35+
- Implicit Default Write Concern
36+
37+
* - 3
38+
- 1
39+
- 4
40+
- 3
41+
- ``{ w: 1 }``
42+
43+
* - 4
44+
- 1
45+
- 5
46+
- 3
47+
- ``{ w: "majority" }``
48+
49+
- The first example has 3 non-arbiters and 1 arbiter for a total of 4
50+
voting nodes. The majority of voting nodes (1 plus half of 4) is 3.
51+
The number of non-arbiters (3) is less than or equal to the majority
52+
of voting nodes, resulting in an implicit write concern of
53+
``{ w: 1 }``.
54+
55+
- The second example has 4 non-arbiters and 1 arbiter for a total of 5
56+
voting nodes. The majority of voting nodes (1 plus half of 5, rounded
57+
down) is 3. The number of non-arbiters (4) is greater than the majority
58+
of voting nodes, resulting in an implicit write concern of ``{ w:
59+
"majority" }``.

‎source/reference/mongodb-defaults.txt

-7
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,6 @@ Default Write Concern
220220

221221
.. include:: /includes/5.0-default-wc.rst
222222

223-
.. note::
224-
225-
- With the default write concern, data can be rolled back.
226-
227-
- This write concern :red:`does not` guarantee :ref:`causal
228-
consistency <sessions>`.
229-
230223
.. _mongodb-default-wc-txns:
231224

232225
.. _mongodb-default-wc-outside-transactions:

‎source/reference/write-concern.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ available:
8282
the :ref:`calculated majority <calculating-majority-count>` of
8383
the data-bearing voting members (i.e. primary and secondaries
8484
with :rsconf:`members[n].votes` greater than ``0``).
85-
``w: majority`` is the default write concern for *most* MongoDB
86-
configurations. See :ref:`wc-default-behavior`.
85+
``{ w: "majority" }`` is the default write concern for *most* MongoDB
86+
deployments. See :ref:`wc-default-behavior`.
8787

8888
For example, consider a replica set with 3 voting members,
8989
Primary-Secondary-Secondary (P-S-S). For this replica set,

‎source/release-notes/5.0.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -667,12 +667,12 @@ Implicit Default Write Concern
667667

668668
.. include:: /includes/5.0-default-wc.rst
669669

670-
This default :doc:`write concern </reference/write-concern>` provides a
671-
stronger durability guarantee in the event of an election, or if replica
672-
set members become unavailable.
670+
The ``{ w: "majority" }`` default :doc:`write concern
671+
</reference/write-concern>` provides a stronger durability guarantee in
672+
the event of an election, or if replica set members become unavailable.
673673

674674
The :writeconcern:`w: majority <"majority">` write concern may impact
675-
peformance since writes will only be acknowledged once a
675+
performance since writes will only be acknowledged once a
676676
:ref:`calculated majority <calculating-majority-count>` of replica set
677677
members have executed and persisted the write to disk.
678678

0 commit comments

Comments
 (0)