-
Notifications
You must be signed in to change notification settings - Fork 43
DOCSP-47041: Causal consistency #623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
6c9b182
3b5d5ce
ca1e821
213fdb1
2a2536f
85b27b8
ae6ae08
22f79b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -28,14 +28,10 @@ error, the driver cancels the transaction and discards all data changes | |||||||||||||
before they ever become visible. | ||||||||||||||
|
||||||||||||||
In MongoDB, transactions run within logical **sessions**. A | ||||||||||||||
:manual:`session </reference/server-sessions/>` is a grouping of related | ||||||||||||||
read or write operations that you intend to run sequentially. Sessions | ||||||||||||||
enable :manual:`causal consistency | ||||||||||||||
</core/read-isolation-consistency-recency/#causal-consistency>` for a | ||||||||||||||
group of operations or allow you to execute operations in an | ||||||||||||||
:website:`ACID transaction </basics/acid-transactions>`. MongoDB | ||||||||||||||
guarantees that the data involved in your transaction operations remains | ||||||||||||||
consistent, even if the operations encounter unexpected errors. | ||||||||||||||
session is a grouping of related read or write operations that you | ||||||||||||||
intend to run sequentially. Sessions allow you to run operations | ||||||||||||||
in an ACID-compliant transaction, which is a transaction that meets | ||||||||||||||
an expectation of atomicity, consistency, isolation, and durability. | ||||||||||||||
|
||||||||||||||
When using the {+driver-short+}, you can create a new session from a | ||||||||||||||
``MongoClient`` instance as a ``ClientSession`` type. We recommend that you reuse | ||||||||||||||
|
@@ -54,6 +50,56 @@ instantiating a new client each time. | |||||||||||||
You must include the ``session`` as a parameter for any operations that you | ||||||||||||||
want to include in a transaction. | ||||||||||||||
|
||||||||||||||
Causal Consistency | ||||||||||||||
~~~~~~~~~~~~~~~~~~ | ||||||||||||||
|
||||||||||||||
MongoDB enables **causal consistency** in client sessions. | ||||||||||||||
The causal consistency model guarantees that operations within a session | ||||||||||||||
run in a causal order. Additionally, clients observe results that | ||||||||||||||
are consistent with the causal relationships, or the dependencies between | ||||||||||||||
operations. If you perform a series of operations where one operation | ||||||||||||||
logically depends on the result of another, any subsequent | ||||||||||||||
reads reflect the dependent relationship. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. S: Clarify that this is giving an example of the preceding descriptions
Suggested change
|
||||||||||||||
|
||||||||||||||
The following table describes the guarantees that causally | ||||||||||||||
consistent sessions provide: | ||||||||||||||
|
||||||||||||||
.. list-table:: | ||||||||||||||
:widths: 40 60 | ||||||||||||||
:header-rows: 1 | ||||||||||||||
|
||||||||||||||
* - Guarantee | ||||||||||||||
- Description | ||||||||||||||
|
||||||||||||||
* - Read your writes | ||||||||||||||
- Read operations reflect the results of preceding write operations. | ||||||||||||||
|
||||||||||||||
* - Monotonic reads | ||||||||||||||
- Read operations do not return results that reflect an earlier data state than | ||||||||||||||
a preceding read operation. | ||||||||||||||
|
||||||||||||||
* - Monotonic writes | ||||||||||||||
- The driver runs write operations that logically must precede other write operations | ||||||||||||||
before these dependent writes. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a little confusing to me. Would it make sense to simplify it to something like this?
Suggested change
An example might help make this more clear as well |
||||||||||||||
|
||||||||||||||
* - Writes follow reads | ||||||||||||||
- The driver runs write operations that logically must follow other read operations | ||||||||||||||
after these reads. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the above, could this be simplified and/or have an example added? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reworded and added an example, let me know what you think! |
||||||||||||||
|
||||||||||||||
In a causally consistent session, MongoDB ensures a | ||||||||||||||
causal relationship between the following operations: | ||||||||||||||
|
||||||||||||||
- Read operations that have a ``MAJORITY`` read concern | ||||||||||||||
- Write operations that have a ``MAJORITY`` write concern | ||||||||||||||
|
||||||||||||||
.. tip:: | ||||||||||||||
|
||||||||||||||
To learn more about the concepts mentioned in this section, see the | ||||||||||||||
following {+mdb-server+} manual entries: | ||||||||||||||
|
||||||||||||||
- :manual:`Causal Consistency </core/read-isolation-consistency-recency/#causal-consistency>` | ||||||||||||||
- :manual:`Causal Consistency and Read and Write Concerns </core/causal-consistency-read-write-concerns/>` | ||||||||||||||
|
||||||||||||||
Methods | ||||||||||||||
------- | ||||||||||||||
|
||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Not sure that "additionally" is necessary here