Skip to content

Commit ca8c965

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 7fea4ed commit ca8c965

10 files changed

+420
-105
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,7 +50,7 @@ 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

@@ -62,6 +62,18 @@ For the purposes of backups,
6262

6363
- .. include:: /includes/extracts/wt-fsync-lock-compatibility.rst
6464

65+
Write Concern
66+
~~~~~~~~~~~~~
67+
68+
Hidden replica set members can acknowledge write operations issued
69+
with :writeconcern:`w: \<number\> <\<number\>>`. For write operations
70+
isued with :writeconcern:`w : "majority" <"majority">`, however,
71+
hidden members must also be voting members (i.e. :rsconf:`members[n].votes`
72+
greater than ``0``) to acknowledge the ``"majority"`` write operation.
73+
Non-voting replica set members (i.e. :rsconf:`members[n].votes`
74+
is ``0``) cannot contribute to acknowledging write operations with
75+
``majority`` write concern.
76+
6577
Further Reading
6678
---------------
6779

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,22 @@ Priority 0 Replica Set Members
1212
:depth: 1
1313
:class: singlecol
1414

15-
A *priority 0* member is a secondary that **cannot** become
16-
:term:`primary`. *Priority 0* members cannot *trigger*
17-
:term:`elections <election>`. Otherwise these members function as
18-
normal secondaries. A *priority 0* member maintains a copy of the data
19-
set, accepts read operations, and votes in elections. Configure a
20-
*priority 0* member to prevent :term:`secondaries <secondary>` from
15+
A :rsconf:`priority 0 <members[n].priority>` member is a member that
16+
**cannot** become :term:`primary` and **cannot** trigger
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.
24+
25+
Other than the aforementioned restrictions, secondaries that have
26+
:rsconf:`priority 0 <members[n].priority>` function as normal
27+
secondaries: they maintains a copy of the data set, accept read
28+
operations, and vote in elections.
29+
30+
Configure a secondary to have *priority 0* to prevent it from
2131
becoming primary, which is particularly useful in multi-data center
2232
deployments.
2333

source/core/replica-set-rollbacks.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ To read the contents of the rollback files, use :doc:`bsondump
6060
of their applications, administrators can decide the next course of
6161
action to take.
6262

63+
.. _rollback-avoid:
64+
6365
Avoid Replica Set Rollbacks
6466
---------------------------
6567

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

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

13-
From the perspective of a client application, whether a MongoDB
14-
instance is running as a single server (i.e. "standalone") or a
15-
:term:`replica set` is transparent. However, replica sets offer some
16-
configuration options for write. [#sharded-clusters]_
17-
18-
.. [#sharded-clusters] :term:`Sharded clusters <sharded cluster>` where the
19-
shards are also replica sets provide the same configuration options
20-
with regards to write and read operations.
21-
22-
.. TODO: remove footnote
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`.
2363

2464
Verify Write Operations to Replica Sets
2565
---------------------------------------
2666

27-
For a replica set, the default :doc:`write concern
28-
</reference/write-concern>` requests acknowledgement only from the primary.
29-
You can, however, override this default write concern, such as to
30-
confirm write operations on a specified number of the replica set
31-
members.
32-
33-
.. include:: /images/crud-write-concern-w2.rst
34-
35-
To override the default write concern, specify a write concern with
36-
each write operation. For example, the following method includes a
37-
write concern that specifies that the method return only after the
38-
write propagates to the primary and at least one secondary or the
39-
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.
4072

4173
.. code-block:: javascript
4274

4375
db.products.insert(
4476
{ item: "envelopes", qty : 100, type: "Clasp" },
45-
{ writeConcern: { w: 2, wtimeout: 5000 } }
77+
{ writeConcern: { w: "majority" , wtimeout: 5000 } }
4678
)
4779

48-
You can include a timeout threshold for a write concern. This prevents
49-
write operations from blocking indefinitely if the write concern is
50-
unachievable. For example, if the write concern requires
51-
acknowledgement from 4 members of the replica set and the replica set
52-
has only available 3 members, the operation blocks until those members
53-
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`.
54105

55106
.. seealso::
56107
: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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ Replica Set Configuration Fields
265265
read operations (i.e. queries) from ever reaching this host by
266266
way of secondary :term:`read preference`.
267267

268+
Hidden members can acknowledge write operations
269+
issued with :ref:`write-concern`. For write operations issued
270+
with :writeconcern:`"majority"` write concern, the member must
271+
also be a voting member (i.e. :rsconf:`~members[n].votes` is
272+
greater than ``0``).
273+
268274
.. seealso::
269275
:ref:`Hidden Replica Set Members <replica-set-hidden-members>`
270276

@@ -292,6 +298,12 @@ Replica Set Configuration Fields
292298
continue to call elections until the highest priority available
293299
member becomes primary.
294300

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

@@ -332,6 +344,14 @@ Replica Set Configuration Fields
332344
of the data that reflects the state of the data at some time in
333345
the past.
334346

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

@@ -362,6 +382,9 @@ Replica Set Configuration Fields
362382

363383
.. include:: /includes/members-used-to-allow-multiple-votes.rst
364384

385+
Members with ``0`` votes cannot acknowledge write operations
386+
issued with a :ref:`write-concern` of :writeconcern:`majority`.
387+
365388
``settings``
366389
~~~~~~~~~~~~
367390

0 commit comments

Comments
 (0)