1
- MongoDB enables **causal consistency ** in client sessions.
2
- The causal consistency model guarantees that operations within a session
3
- run in a causal order. Clients observe results that are consistent
1
+ MongoDB enables **causal consistency ** in certain client
2
+ sessions. The causal consistency model guarantees that in a
3
+ distributed system, operations within a session run in a causal
4
+ order. Clients observe results that are consistent
4
5
with the causal relationships, or the dependencies between
5
6
operations. For example, if you perform a series of operations where
6
7
one operation logically depends on the result of another, any subsequent
7
8
reads reflect the dependent relationship.
8
9
10
+ To guarantee causal consistency, client sessions must fulfill the
11
+ following requirements:
12
+
13
+ - When starting a session, the driver must enable the causal consistency
14
+ option. This option is enabled by default.
15
+
16
+ - Operations must run in a single session on a single thread. Otherwise,
17
+ the sessions or threads must communicate the operation time and cluster
18
+ time values to each other. To view an example of two sessions that communicate
19
+ these values, see the :manual: `Causal Consistency examples </core/read-isolation-consistency-recency/#examples> `
20
+ in the {+mdb-server+} manual.
21
+
22
+ - You must use a |majority-rc | read concern.
23
+
24
+ - You must use a |majority-wc | write concern. This is the default write concern
25
+ value.
26
+
9
27
The following table describes the guarantees that causally
10
28
consistent sessions provide:
11
29
@@ -24,27 +42,21 @@ consistent sessions provide:
24
42
a preceding read operation.
25
43
26
44
* - Monotonic writes
27
- - If a write operation must precede other write operations, the driver
45
+ - If a write operation must precede other write operations, the server
28
46
runs this write operation first.
29
47
30
48
For example, if you call |insert-one-method | to insert a document, then call
31
- |update-one-method | to modify the inserted document, the driver runs the
49
+ |update-one-method | to modify the inserted document, the server runs the
32
50
insert operation first.
33
51
34
52
* - Writes follow reads
35
- - If a write operation must follow other read operations, the driver runs
53
+ - If a write operation must follow other read operations, the server runs
36
54
the read operations first.
37
55
38
56
For example, if you call |find-one-method | to retrieve a document, then call
39
- |delete-one-method | to delete the retrieved document, the driver runs the find
57
+ |delete-one-method | to delete the retrieved document, the server runs the find
40
58
operation first.
41
59
42
- In a causally consistent session, MongoDB ensures a
43
- causal relationship between the following operations:
44
-
45
- - Read operations that have a |majority-rc | read concern
46
- - Write operations that have a |majority-wc | write concern
47
-
48
60
.. tip ::
49
61
50
62
To learn more about the concepts mentioned in this section, see the
0 commit comments