Read Concern "local"
A query with read concern "local"
returns data from the instancewith no guarantee that the data has been written to a majority of thereplica set members (i.e. may be rolled back).
Read concern "local"
is the default for:
- read operations against primary
- read operations against secondaries if the reads are associated withcausally consistent sessions.
Regardless of the read concern level, the most recent data on anode may not reflect the most recent version of the data in the system.
Causally Consistent Sessions
Read concern local
is available for use with causallyconsistent sessions.
Read Concern "local" and Transactions
You set the read concern at the transaction level, not at theindividual operation level. To set the read concern for transactions,see Transactions and Read Concern.
Example
Consider the following timeline of a write operation Write0 toa three member replica set:
Note
For simplification, the example assumes:
- All writes prior to Write0 have been successfullyreplicated to all members.
- Writeprev is the previous write before Write0.
- No other writes have occured after Write0.
Time | Event | Most Recent Write | Most Recent w: “majority” write |
---|---|---|---|
t0 | Primary applies Write0 | Primary: Write0Secondary1: WriteprevSecondary2: Writeprev | Primary: WriteprevSecondary1: WriteprevSecondary2: Writeprev |
t1 | Secondary1 applies write0 | Primary: Write0Secondary1: Write0Secondary2: Writeprev | Primary: WriteprevSecondary1: WriteprevSecondary2: Writeprev |
t2 | Secondary2 applies write0 | Primary: Write0Secondary1: Write0Secondary2: Write0 | Primary: WriteprevSecondary1: WriteprevSecondary2: Writeprev |
t3 | Primary is aware of successful replication to Secondary1 and sends acknowledgement to client | Primary: Write0Secondary1: Write0Secondary2: Write0 | Primary: Write0Secondary1: WriteprevSecondary2: Writeprev |
t4 | Primary is aware of successful replication to Secondary2 | Primary: Write0Secondary1: Write0Secondary2: Write0 | Primary: Write0Secondary1: WriteprevSecondary2: Writeprev |
t5 | Secondary1 receives notice (through regular replication mechanism) to update its snapshot of its most recent w: “majority” write | Primary: Write0Secondary1: Write0Secondary2: Write0 | Primary: Write0Secondary1: Write0Secondary2: Writeprev |
t6 | Secondary2 receives notice (through regular replication mechanism) to update its snapshot of its most recent w: “majority” write | Primary: Write0Secondary1: Write0Secondary2: Write0 | Primary: Write0Secondary1: Write0Secondary2: Write0 |
Then, the following tables summarizes the state of the data that a readoperation with "local"
read concern would see attime T
.
Read Target | Time T | State of Data |
---|---|---|
Primary | After t0 | Data reflects Write0. |
Secondary1 | Before t1 | Data reflects Writeprev |
Secondary1 | After t1 | Data reflects Write0 |
Secondary2 | Before t2 | Data reflects Writeprev |
Secondary2 | After t2 | Data reflects Write0 |