function checkMonotonicReads (int numberOfValues) {
firstReadValue = read (key)
for i = 1 to numberOfValues do
newReadValue = read (key)
if newReadValue >= firstReadValue then
log (monotonic reads complied)
else
log (monotonic reads violated)
}function write (int numberOfValues) {
for i = 1 to numberOfValues do
write (key, i)
}readConcern: {level: <"majority" | "local">, afterClusterTime: <timestamp>}Hi
If I understand correctly, your test has these two parallel parts:
Is this the correct understanding of your test setup?
If it is correct, the first thing that needed to be clear is that causal consistency guarantees are valid only for a single session. That is, if you have another parallel session going on that modifies the documents at the same time, the session will see the parallel update. I believe this is what you’re seeing.
This is mentioned in a note in the page you linked: “Operations within a client session are not isolated from operations outside the session.”
The main feature of causal consistency is to be able to provide causality guarantees in a replica set, e.g. when you’re writing to the primary, and reading from a secondary. Previously, even if you do your writes with w: majority and reads with readConcern: majority, there is no guarantee the causality of your reads & writes. Causal consistency provides this guarantee across the replica set.
In the tests with the read concern level “local” I have found violations of the monotonic read guarantees. So for example the value 5 was read first and afterwards the value 3 was read.
Assuming 5 is supposed to be after 3, this would be a violation if the read and writes are performed within a single, causally consistent session. If 3 was written from outside the session, it is not a violation because the guarantee is not valid if another thread modifies the document.
What takes precedence? The guarantees of causal consistent sessions or the limitations of the read concern level “local”?
If the session was created with causal consistency, then the causality guarantees would take precedence over read concerns. Note that within a session, you can specify different read concerns for different read operations.
You may find the following links interesting:
Best regards
Kevin
Is this the correct understanding of your test setup?
Applications must ensure that only one thread at a time executes these operations in a client session.