Skip to content

Commit 03ba6fa

Browse files
committed
Reorg read concern in prep for 4.0
1 parent bf53f4a commit 03ba6fa

8 files changed

+655
-117
lines changed

config/sphinx_local.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ theme:
6868
- /reference/operator/query-modifier
6969
- /reference/operator/update
7070
- /reference/replication
71+
- /reference/read-concern
7172
- /reference/security
7273
- /reference/sharding
7374
- /reference/write-concern
Lines changed: 90 additions & 0 deletions
Loading
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
Consider the following timeline of a write operation Write\ :sub:`0` to
2+
a three member replica set:
3+
4+
.. note::
5+
6+
For simplification, the example assumes:
7+
8+
- All writes prior to Write\ :sub:`0` have been successfully
9+
replicated to all members.
10+
11+
- Write\ :sub:`prev` is the previous write before Write\ :sub:`0`.
12+
13+
- No other writes have occured after Write\ :sub:`0`.
14+
15+
.. figure:: /images/read-concern-write-timeline.svg
16+
:alt: Timeline of a write operation to a three member replica set.
17+
:figwidth: 330px
18+
19+
.. list-table::
20+
:header-rows: 1
21+
:widths: 10 45 25 25
22+
23+
* - Time
24+
- Event
25+
- Most Recent Write
26+
- Most Recent w: "majority" write
27+
28+
* - t\ :sub:`0`
29+
- Primary applies Write\ :sub:`0`
30+
31+
- | **Primary**: Write\ :sub:`0`
32+
| **Secondary**\ :sub:`1`: Write\ :sub:`prev`
33+
| **Secondary**\ :sub:`2`: Write\ :sub:`prev`
34+
35+
- | **Primary**: Write\ :sub:`prev`
36+
| **Secondary**\ :sub:`1`: Write\ :sub:`prev`
37+
| **Secondary**\ :sub:`2`: Write\ :sub:`prev`
38+
39+
40+
41+
* - t\ :sub:`1`
42+
- Secondary\ :sub:`1` applies write\ :sub:`0`
43+
44+
- | **Primary**: Write\ :sub:`0`
45+
| **Secondary**\ :sub:`1`: Write\ :sub:`0`
46+
| **Secondary**\ :sub:`2`: Write\ :sub:`prev`
47+
48+
49+
- | **Primary**: Write\ :sub:`prev`
50+
| **Secondary**\ :sub:`1`: Write\ :sub:`prev`
51+
| **Secondary**\ :sub:`2`: Write\ :sub:`prev`
52+
53+
* - t\ :sub:`2`
54+
- Secondary\ :sub:`2` applies write\ :sub:`0`
55+
- | **Primary**: Write\ :sub:`0`
56+
| **Secondary**\ :sub:`1`: Write\ :sub:`0`
57+
| **Secondary**\ :sub:`2`: Write\ :sub:`0`
58+
59+
60+
- | **Primary**: Write\ :sub:`prev`
61+
| **Secondary**\ :sub:`1`: Write\ :sub:`prev`
62+
| **Secondary**\ :sub:`2`: Write\ :sub:`prev`
63+
64+
* - t\ :sub:`3`
65+
- Primary is aware of successful replication to Secondary\ :sub:`1` and sends acknowledgement to client
66+
- | **Primary**: Write\ :sub:`0`
67+
| **Secondary**\ :sub:`1`: Write\ :sub:`0`
68+
| **Secondary**\ :sub:`2`: Write\ :sub:`0`
69+
70+
- | **Primary**: Write\ :sub:`0`
71+
| **Secondary**\ :sub:`1`: Write\ :sub:`prev`
72+
| **Secondary**\ :sub:`2`: Write\ :sub:`prev`
73+
74+
* - t\ :sub:`4`
75+
- Primary is aware of successful replication to Secondary\ :sub:`2`
76+
77+
- | **Primary**: Write\ :sub:`0`
78+
| **Secondary**\ :sub:`1`: Write\ :sub:`0`
79+
| **Secondary**\ :sub:`2`: Write\ :sub:`0`
80+
81+
- | **Primary**: Write\ :sub:`0`
82+
| **Secondary**\ :sub:`1`: Write\ :sub:`prev`
83+
| **Secondary**\ :sub:`2`: Write\ :sub:`prev`
84+
85+
* - t\ :sub:`5`
86+
- Secondary\ :sub:`1` receives notice (through regular replication mechanism) to update its snapshot of its most recent w: "majority" write
87+
88+
- | **Primary**: Write\ :sub:`0`
89+
| **Secondary**\ :sub:`1`: Write\ :sub:`0`
90+
| **Secondary**\ :sub:`2`: Write\ :sub:`0`
91+
92+
- | **Primary**: Write\ :sub:`0`
93+
| **Secondary**\ :sub:`1`: Write\ :sub:`0`
94+
| **Secondary**\ :sub:`2`: Write\ :sub:`prev`
95+
96+
* - t\ :sub:`6`
97+
- Secondary\ :sub:`2` receives notice (through regular replication mechanism) to update its snapshot of its most recent w: "majority" write
98+
99+
- | **Primary**: Write\ :sub:`0`
100+
| **Secondary**\ :sub:`1`: Write\ :sub:`0`
101+
| **Secondary**\ :sub:`2`: Write\ :sub:`0`
102+
103+
- | **Primary**: Write\ :sub:`0`
104+
| **Secondary**\ :sub:`1`: Write\ :sub:`0`
105+
| **Secondary**\ :sub:`2`: Write\ :sub:`0`
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
.. default-domain:: mongodb
2+
3+
.. class:: hidden
4+
5+
.. readconcern:: "available"
6+
7+
============================
8+
Read Concern ``"available"``
9+
============================
10+
11+
.. meta::
12+
:description: read concern, available read concern, read isolation
13+
:keywords: read concern, available read concern, read isolation
14+
15+
.. versionadded:: 3.6
16+
17+
A query with read concern `"available"` returns the instance's most
18+
recent data. Read concern `"available"` provides no guarantee that the
19+
data has been written to a majority of the replica set members (i.e.
20+
may be rolled back).
21+
22+
Read concern `"available"` is the default for reads against secondaries
23+
if the reads are not associated with :ref:`causally consistent sessions
24+
<sessions>`.
25+
26+
For a sharded cluster, :readconcern:`"available"` read concern provides
27+
greater tolerance for partitions since it does not wait to ensure
28+
consistency guarantees. However, a query with
29+
:readconcern:`"available"` read concern may return orphan documents if
30+
the shard is undergoing chunk migrations since the
31+
:readconcern:`"available"` read concern, unlike :readconcern:`"local"`
32+
read concern, does not contact the shard's primary nor the config
33+
servers for updated :doc:`metadata
34+
</core/sharded-cluster-config-servers>`.
35+
36+
For unsharded collections (including collections in a standalone
37+
deployment or a replica set deployment), :readconcern:`"local"` and
38+
:readconcern:`"available"` read concerns behave identically.
39+
40+
.. include:: /includes/fact-readConcern-most-recent-data-in-node.rst
41+
42+
.. seealso:: :parameter:`orphanCleanupDelaySecs`
43+
44+
Causally Consistent Sessions
45+
----------------------------
46+
47+
Read concern :readconcern:`available` is unavailable for use with
48+
causally consistent sessions.
49+
50+
Example
51+
-------
52+
53+
.. include:: /includes/fact-read-concern-write-timeline.rst
54+
55+
Then, the following tables summarizes the state of the data that a read
56+
operation with :readconcern:`"available"` read concern would see at
57+
time ``T``.
58+
59+
.. figure:: /images/read-concern-write-timeline.svg
60+
:alt: Timeline of a write operation to a three member replica set.
61+
:figwidth: 330px
62+
63+
.. list-table::
64+
:header-rows: 1
65+
:widths: 40 30 30
66+
67+
* - Read Target
68+
- Time ``T``
69+
- State of Data
70+
71+
* - Primary
72+
- After t\ :sub:`0`
73+
- Data reflects Write\ :sub:`0`.
74+
75+
* - Secondary\ :sub:`1`
76+
- Before t\ :sub:`1`
77+
- Data reflects Write\ :sub:`prev`
78+
79+
* - Secondary\ :sub:`1`
80+
- After t\ :sub:`1`
81+
- Data reflects Write\ :sub:`0`
82+
83+
* - Secondary\ :sub:`2`
84+
- Before t\ :sub:`2`
85+
- Data reflects Write\ :sub:`prev`
86+
87+
* - Secondary\ :sub:`2`
88+
- After t\ :sub:`2`
89+
- Data reflects Write\ :sub:`0`
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
.. default-domain:: mongodb
2+
3+
.. class:: hidden
4+
5+
.. readconcern:: "linearizable"
6+
7+
===============================
8+
Read Concern ``"linearizable"``
9+
===============================
10+
11+
.. versionadded:: 3.4
12+
13+
The query returns data that reflects all successful
14+
majority-acknowledged writes that completed prior to the start of the
15+
read operation. The query may wait for concurrently executing writes to
16+
propagate to a majority of replica set members before returning results.
17+
18+
If a majority of your replica set members crash and restart after the
19+
read operation, documents returned by the read operation are durable if
20+
:rsconf:`writeConcernMajorityJournalDefault` is set to the default
21+
state of ``true``.
22+
23+
.. include:: /includes/extracts/no-journaling-rollback.rst
24+
25+
You can specify linearizable read concern for read operations on
26+
the :replstate:`primary <PRIMARY>` only.
27+
28+
Linearizable read concern guarantees only apply if read
29+
operations specify a query filter that uniquely identifies a
30+
single document.
31+
32+
.. tip::
33+
34+
Always use ``maxTimeMS`` with linearizable read concern in case a
35+
majority of data bearing members are unavailable. ``maxTimeMS``
36+
ensures that the operation does not block indefinitely and instead
37+
ensures that the operation returns an error if the read concern
38+
cannot be fulfilled.
39+
40+
Causally Consistent Sessions
41+
----------------------------
42+
43+
Read concern :readconcern:`linearizable` is unavailable for use with
44+
causally consistent sessions.
45+
46+
Real Time Order
47+
---------------
48+
49+
Combined with :writeconcern:`"majority"` write concern,
50+
:readconcern:`"linearizable"` read concern enables multiple threads to
51+
perform reads and writes on a single document as if a single thread
52+
performed these operations in real time; that is, the corresponding
53+
schedule for these reads and writes is considered linearizable.
54+
55+
Read Your Own Writes
56+
--------------------
57+
58+
.. versionchanged:: 3.6
59+
60+
.. include:: /includes/fact-read-own-writes.rst
61+
62+
Performance Comparisons
63+
-----------------------
64+
65+
Unlike :readconcern:`"majority"`, :readconcern:`"linearizable"` read
66+
concern confirms with secondary members that the read operation is
67+
reading from a primary that is capable of confirming writes with
68+
:writeconcern:`{ w: "majority" } <"majority">` write concern.
69+
[#edge-cases-2-primaries]_ As such, reads with linearizable read
70+
concern may be significantly slower than reads with
71+
:readconcern:`"majority"` or :readconcern:`"local"` read concerns.
72+
73+
Always use ``maxTimeMS`` with linearizable read concern in case a
74+
majority of data bearing members are unavailable. ``maxTimeMS`` ensures
75+
that the operation does not block indefinitely and instead ensures that
76+
the operation returns an error if the read concern cannot be fulfilled.
77+
78+
For example:
79+
80+
.. code-block:: javascript
81+
82+
db.restaurants.find( { _id: 5 } ).readConcern("linearizable").maxTimeMS(10000)
83+
84+
db.runCommand( {
85+
find: "restaurants",
86+
filter: { _id: 5 },
87+
readConcern: { level: "linearizable" },
88+
maxTimeMS: 10000
89+
} )
90+
91+
.. [#edge-cases-2-primaries]
92+
93+
.. include:: /includes/footnote-two-primaries-edge-cases.rst
94+

0 commit comments

Comments
 (0)