Skip to content

Commit 88139bd

Browse files
committed
DOCS-12171: Clarify that only data-bearing members vote, hidden and delayed secondaries eligible. Stretch to clean up replica set write concern documentation
1 parent 1e433d1 commit 88139bd

10 files changed

+397
-80
lines changed

source/core/replica-set-delayed-member.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ When choosing the amount of delay, consider that the amount of delay:
5656
- must be *smaller* than the capacity of the oplog. For more
5757
information on oplog size, see :ref:`replica-set-oplog-sizing`.
5858

59+
Write Concern
60+
~~~~~~~~~~~~~
61+
62+
Delayed replica set members can acknowledge write operations issued
63+
with :writeconcern:`w: \<number\> <\<number\>>`. For write operations
64+
isued with :writeconcern:`w : "majority" <"majority">`, however,
65+
delayed members must also be voting members (i.e.
66+
:rsconf:`members[n].votes` greater than ``0``) to acknowledge the
67+
``"majority"`` write operation. Non-voting replica set members
68+
(i.e. :rsconf:`members[n].votes` is ``0``) cannot contribute to
69+
acknowledging write operations with ``majority`` write concern.
70+
71+
Delayed secondaries can return write acknowledgment no earlier than the
72+
configured :rsconf:`~members[n].slaveDelay`.
73+
5974
Sharding
6075
~~~~~~~~
6176

source/core/replica-set-hidden-member.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,24 @@ Voting
5050

5151
Hidden members *may* vote in replica set elections. If you stop a
5252
voting hidden member, ensure that the set has an active majority or the
53-
:term:`primary` will step down.
53+
:term:`primary` will step down.
5454

5555
For the purposes of backups,
5656

5757
- .. include:: /includes/extracts/wt-fsync-lock-compatibility.rst
5858

59+
Write Concern
60+
~~~~~~~~~~~~~
61+
62+
Hidden replica set members can acknowledge write operations issued
63+
with :writeconcern:`w: \<number\> <\<number\>>`. For write operations
64+
isued with :writeconcern:`w : "majority" <"majority">`, however,
65+
hidden members must also be voting members (i.e. :rsconf:`members[n].votes`
66+
greater than ``0``) to acknowledge the ``"majority"`` write operation.
67+
Non-voting replica set members (i.e. :rsconf:`members[n].votes`
68+
is ``0``) cannot contribute to acknowledging write operations with
69+
``majority`` write concern.
70+
5971
Further Reading
6072
---------------
6173

source/core/replica-set-priority-0-member.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ Priority 0 Replica Set Members
1414

1515
A :rsconf:`priority 0 <members[n].priority>` member is a member that
1616
**cannot** become :term:`primary` and **cannot** trigger
17-
:term:`elections <election>`.
17+
:term:`elections <election>`. Priority 0 members can acknowledge write
18+
operations issued with :ref:`write concern <write-concern>` of
19+
``w : <number>``. For ``"majority"`` write concern, the priority 0
20+
member must also be a voting member (i.e. :rsconf:`members[n].votes` is
21+
greater than ``0``) to acknowledge the write. Non-voting replica set
22+
members (i.e. :rsconf:`members[n].votes` is ``0``) cannot contribute to
23+
acknowledging write operations with ``"majority"`` write concern.
1824

1925
Other than the aforementioned restrictions, secondaries that have
2026
:rsconf:`priority 0 <members[n].priority>` function as normal

source/core/replica-set-rollbacks.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ Starting in version 4.0, MongoDB adds the parameter
6868
:parameter:`createRollbackDataFiles` to control whether or not data
6969
files are written during rollback.
7070

71+
.. _rollback-avoid:
72+
7173
Avoid Replica Set Rollbacks
7274
---------------------------
7375

source/core/replica-set-write-concern.txt

Lines changed: 81 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,98 @@ Write Concern for Replica Sets
1010
:depth: 1
1111
:class: singlecol
1212

13-
Write concern describes the level of acknowledgement requested from
14-
MongoDB for write operations.
13+
:ref:`Write concern <write-concern>` for replica sets describe the
14+
number of data-bearing members (i.e. the primary and secondaries,
15+
but not arbiters) that must acknowledge a write operation before the
16+
operation returns as successful. A member can only acknowledge a
17+
write operation after it has received and applied the write
18+
successfully.
19+
20+
For replica sets, the default write concern of
21+
:writeconcern:`w: 1 </<number/>>` requires that only the primary
22+
replica set member acknowledge the write before returning
23+
write concern acknowledgment. You can specify an integer
24+
value greater than ``1`` to require acknowledgment from the primary and
25+
as many secondaries as needed to meet the specified value, up to the
26+
total number of data-bearing members in the replica set.
27+
28+
Write operations with a write concern of :writeconcern:`"majority"`
29+
require acknowledgment from a simple majority of data-bearing
30+
voting replica set members (i.e. :rsconf:`members[n].votes` is greater
31+
than ``0`` and :rsconf:`members[n].arbiterOnly` is ``false``). For
32+
clusters where members have :ref:`journaling <journaling-internals>`
33+
enabled, combining ``"majority"`` write concern with
34+
:writeconcern:`j : true <j>` can prevent
35+
:ref:`rollback <replica-set-rollbacks>` of write concern acknowledged
36+
data.
37+
38+
For complete documentation on write acknowledgment
39+
behavior, see :ref:`wc-ack-behavior`.
40+
41+
.. include:: /images/crud-write-concern-w-majority.rst
42+
43+
An application that issues a write operation that requires
44+
write concern acknowledgment waits until the primary receives
45+
acknowledgment from the required number of members for the specified
46+
write concern. For write concern of ``w`` greater than 1 or
47+
``w : "majority"``, the primary waits until the required number of
48+
secondaries acknowledge the write before returning write concern
49+
acknowledgment. For write concern of ``w: 1``, the primary can return
50+
write concern acknowledgment as soon as it locally applies the write
51+
since it is eligible for contributing to the requested write concern.
52+
53+
The more members that acknowledge a write, the less likely the written
54+
data could roll back if the
55+
:ref:`primary fails <replication-auto-failover>`. However, specifying
56+
a high write concern can increase latency as the client must wait until
57+
it receives the requested level of write concern acknowledgment.
58+
59+
Selecting the ideal write concern for any given write operation depends
60+
on your application's performance goals and data durability
61+
requirements. For more guidance on configuring write concern to
62+
prevent rollbacks, see :ref:`rollback-avoid`.
1563

1664
Verify Write Operations to Replica Sets
1765
---------------------------------------
1866

19-
For a replica set, the default :doc:`write concern
20-
</reference/write-concern>` requests acknowledgement only from the primary.
21-
You can, however, override this default write concern, such as to
22-
confirm write operations on a specified number of the replica set
23-
members.
24-
25-
.. include:: /images/crud-write-concern-w2.rst
26-
27-
To override the default write concern, specify a write concern with
28-
each write operation. For example, the following method includes a
29-
write concern that specifies that the method return only after the
30-
write propagates to the primary and at least one secondary or the
31-
method times out after 5 seconds.
67+
The following operation includes the ``writeConcern`` option to
68+
the :method:`~db.collection.insert()` method. The operation specifies
69+
:writeconcern:`"majority"` write concern and a 5 second timeout using
70+
the :ref:`wc-wtimeout` write concern parameter so that the operation
71+
does not block indefinitely.
3272

3373
.. code-block:: javascript
3474

3575
db.products.insert(
3676
{ item: "envelopes", qty : 100, type: "Clasp" },
37-
{ writeConcern: { w: 2, wtimeout: 5000 } }
77+
{ writeConcern: { w: "majority" , wtimeout: 5000 } }
3878
)
3979

40-
You can include a timeout threshold for a write concern. This prevents
41-
write operations from blocking indefinitely if the write concern is
42-
unachievable. For example, if the write concern requires
43-
acknowledgement from 4 members of the replica set and the replica set
44-
has only available 3 members, the operation blocks until those members
45-
become available. See :ref:`wc-wtimeout`.
80+
The application waits until the primary returns write concern
81+
acknowledgment, indicating that a simple majority of data-bearing voting
82+
members acknowledged the write operation. For example, in a 3-member
83+
replica set the operation would require acknowledgment from 2 out of
84+
the 3 members. If the replica set was later scaled to include two
85+
additional voting nodes, the same operation would require
86+
acknowledgment from 3 out of the 5 replica set members. If the
87+
primary does not return write concern acknowledgment within the
88+
``wtimeout`` limit, the write operation fails with a write concern
89+
error.
90+
91+
A write operation that times out waiting for the specified write concern
92+
only indicates that the required number of replica set members did not
93+
acknowledge the write operation within the ``wtimeout`` time period.
94+
It does not necessarily indicate that the primary failed to apply the
95+
write. The data may exist on a subset of replica set nodes at the time
96+
of the write concern error, and can continue replicating until all
97+
nodes in the cluster have that data. Applications should take into
98+
account the potential availability of written data regardless of the
99+
state of write concern acknowledgment.
100+
101+
The exact syntax for specifying write concern depends on the write
102+
operation. Refer to the documentation for the write operation for
103+
instructions on write concern support and syntax. For complete
104+
documentation on write concern, see :ref:`write-concern`.
46105

47106
.. seealso::
48107
:ref:`write-methods-incompatibility`

source/images/crud-write-concern-w-majority.bakedsvg.svg

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.. figure:: /images/crud-write-concern-w-majority.bakedsvg.svg
2+
:alt: Write operation to a replica set with write concern level of ``w: "majority"`` or write to the primary and at least one secondary.
3+
:figwidth: 520px
Lines changed: 125 additions & 0 deletions
Loading

source/reference/replica-configuration.txt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ Replica Set Configuration Fields
261261
read operations (i.e. queries) from ever reaching this host by
262262
way of secondary :term:`read preference`.
263263

264+
Hidden members can acknowledge write operations
265+
issued with :ref:`write-concern`. For write operations issued
266+
with :writeconcern:`"majority"` write concern, the member must
267+
also be a voting member (i.e. :rsconf:`~members[n].votes` is
268+
greater than ``0``).
269+
264270
.. seealso::
265271
:ref:`Hidden Replica Set Members <replica-set-hidden-members>`
266272

@@ -278,7 +284,6 @@ Replica Set Configuration Fields
278284

279285
*Default*: 1.0 for primary/secondary; 0 for arbiters.
280286

281-
282287
A number that indicates the relative eligibility of a member to
283288
become a :term:`primary`.
284289

@@ -295,6 +300,12 @@ Replica Set Configuration Fields
295300
continue to call elections until the highest priority available
296301
member becomes primary.
297302

303+
Members with :rsconf:`~members[n].priority` of ``0`` can
304+
acknowledge write operations issued with :ref:`write-concern`.
305+
For write operations issued with :writeconcern:`"majority"` write
306+
concern, the member must also be a voting member (i.e.
307+
:rsconf:`~members[n].votes` is greater than ``0``).
308+
298309
.. seealso::
299310
:ref:`Replica Set Elections <replica-set-elections>`.
300311

@@ -335,6 +346,14 @@ Replica Set Configuration Fields
335346
of the data that reflects the state of the data at some time in
336347
the past.
337348

349+
Delayed members can contribute to acknowledging write
350+
operations issued with :ref:`write-concern`. However,
351+
they return write acknowledgment no earlier than the configured
352+
delay value. For write operations issued with
353+
:writeconcern:`"majority"` write concern, the member must also be
354+
a voting member (i.e. :rsconf:`~members[n].votes` is greater than
355+
``0``).
356+
338357
.. seealso::
339358
:doc:`/core/replica-set-delayed-member`
340359

@@ -365,6 +384,9 @@ Replica Set Configuration Fields
365384

366385
.. include:: /includes/members-used-to-allow-multiple-votes.rst
367386

387+
Members with ``0`` votes cannot acknowledge write operations
388+
issued with a :ref:`write-concern` of :writeconcern:`majority`.
389+
368390
``settings``
369391
~~~~~~~~~~~~
370392

0 commit comments

Comments
 (0)