-
Notifications
You must be signed in to change notification settings - Fork 44
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
DOCSP-48660: Causal consistency edits #97
base: main
Are you sure you want to change the base?
Changes from 1 commit
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 |
---|---|---|
@@ -1,11 +1,27 @@ | ||
MongoDB enables **causal consistency** in client sessions. | ||
The causal consistency model guarantees that operations within a session | ||
MongoDB enables **causal consistency** in certain client | ||
sessions to guarantee that operations within a session | ||
run in a causal order. Clients observe results that are consistent | ||
with the causal relationships, or the dependencies between | ||
operations. For example, if you perform a series of operations where | ||
one operation logically depends on the result of another, any subsequent | ||
reads reflect the dependent relationship. | ||
|
||
To guarantee causal consistency, client sessions must fulfill the | ||
following requirements: | ||
|
||
- When starting a session, the driver must enable the causal consistency | ||
option. This option is enabled by default. To learn more, see the | ||
:manual:`causalConsistency field </reference/method/Mongo.startSession/#mongodb-method-Mongo.startSession>` | ||
in the {+mdb-server+} manual. | ||
|
||
- Operations must run in a single session on a single thread. Otherwise, | ||
the sessions or threads must communicate the operation time and cluster | ||
time values to each other. | ||
|
||
- You must use a |majority-rc| read concern. | ||
|
||
- You must use a |majority-wc| write concern. | ||
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. Maybe worth calling out that this is the default (similar to the callout about the driver enabling causal consistency by default): https://emptysqua.re/blog/how-to-use-mongodb-causal-consistency/? 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. To clarify, this is for write concern |
||
|
||
The following table describes the guarantees that causally | ||
consistent sessions provide: | ||
|
||
|
@@ -24,26 +40,23 @@ consistent sessions provide: | |
a preceding read operation. | ||
|
||
* - Monotonic writes | ||
- If a write operation must precede other write operations, the driver | ||
- If a write operation must precede other write operations, the server | ||
runs this write operation first. | ||
|
||
For example, if you call |insert-one-method| to insert a document, then call | ||
|update-one-method| to modify the inserted document, the driver runs the | ||
insert operation first. | ||
For example, you can call |insert-one-method| to insert a document, then call | ||
|update-one-method| to modify the inserted document. If a secondary node receives | ||
your update operation and has not yet written the original insert operation to | ||
its :manual:`oplog </reference/glossary/#std-term-oplog>`, this operation is blocked | ||
until the secondary applies the changes from the insert. | ||
|
||
* - Writes follow reads | ||
- If a write operation must follow other read operations, the driver runs | ||
the read operations first. | ||
|
||
For example, if you call |find-one-method| to retrieve a document, then call | ||
|delete-one-method| to delete the retrieved document, the driver runs the find | ||
operation first. | ||
|
||
In a causally consistent session, MongoDB ensures a | ||
causal relationship between the following operations: | ||
|
||
- Read operations that have a |majority-rc| read concern | ||
- Write operations that have a |majority-wc| write concern | ||
For example, you can call |find-one-method| to retrieve a document, then call | ||
|delete-one-method| to delete the retrieved document. The server that receives | ||
the delete waits to run the operation until it applies the changes from the original | ||
find operation. | ||
|
||
.. tip:: | ||
|
||
|
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.
S: Add something like "operations within a session in a distributed system run in a causal order" to make it clear that causal consistency holds with replica sets/nodes