Search code examples
databasemongodbdatabase-replicationsharding

In MongoDB, why is read concern "available" default option for secondaries in non causally consistent sessions?


I am confused about how causal consistency affects the decision of choosing between read-concern "local" vs "available".

Why read-concern "available" is default for secondaries when it is a non causally consistent session ?

I understand how "available" behaves for sharded clusters vs "local" behaves for unsharded collections.

I just cannot make the connection based on reading the documents.

I would really appreciate if someone helped me bridge. Thanks ahead.


Solution

  • Here's a summary of read concern levels in terms of a sharded cluster:

    • majority: only returns data that was written to the majority of voting nodes and will not be rolled back.
    • local: returns data on the local node, but with orphaned documents filtered out. This requires the node to communicate with the shard's primary (if this read is on a secondary), or the config server to service the read. In a degraded sharded cluster, this read may stall indefinitely. This is not an issue for an unsharded collection, though. Possible to return data that could be rolled back.
    • available: returns whatever data that is available. This is to allow read availability as a priority over correctness. Possible to return data that could be rolled back. See Read Concern "available"

    Shard secondaries default to "available" read concern to maintain behaviour compatibility with MongoDB 3.4 (see SERVER-31032)

    Causal consistency can provide different guarantees depending on the read & write concern used (see Causal Consistency and Read and Write Concerns for an exhaustive detail), where a balance between read own writes, monotonic reads, monotonic writes, and writes follow reads can be achieved by using different levels of read & write concerns.

    Since causal consistency provides a semblance of guarantee of data integrity, it is not compatible with "available" read concern, since "available" is meant to provide no guarantee regarding integrity, but to emphasize availability instead.