Read Concern 读取关注"local"

A query with read concern "local" returns data from the instance with no guarantee that the data has been written to a majority of the replica set members (i.e. may be rolled back).带有读取关注点"local"的查询从实例返回数据,但不保证数据已写入大多数副本集成员(即,可能会回滚)。

Read concern "local" is the default for read operations against the primary and secondaries.读关注点"local"是针对主设备和辅助设备的读操作的默认值。

Regardless of the read concern level, the most recent data on a node may not reflect the most recent version of the data in the system.无论读取关注级别如何,节点上的最新数据可能不会反映系统中数据的最新版本。

Availability可用性

Read concern "local" is available for use with or without causally consistent sessions and transactions.读取关注点"local"可与或不与因果一致的会话和事务一起使用。

Read Concern "local" and Transactions读取关注点"local"和事务

You set the read concern at the transaction level, not at the individual operation level. 您可以在事务级别而不是单个操作级别设置读取关注点。To set the read concern for transactions, see Transactions and Read Concern.要设置事务的读取关注点,请参阅事务和读取关注点

Starting in MongoDB 4.4, you can create collections and indexes inside a transaction. 从MongoDB 4.4开始,您可以在事务内创建集合和索引If explicitly creating a collection or an index, the transaction must use read concern "local". 如果显式创建集合或索引,则事务必须使用读取关注点"local"Implicit creation of a collection can use any of the read concerns available for transactions.隐式创建集合可以使用事务可用的任何读取关注点。

Example示例

Consider the following timeline of a write operation Write 0 to a three member replica set:考虑以下写入操作的时间线将0写入三个成员的副本集:

Note注意

For simplification, the example assumes:为了简化,本例假设:

  • All writes prior to Write 0 have been successfully replicated to all members.写入0之前的所有写入都已成功复制到所有成员。
  • Write prev is the previous write before Write 0.写入prev是写入0之前的上一次写入。
  • No other writes have occured after Write 0.写入0后未发生其他写入。
Timeline of a write operation to a three member replica set.
TimeEventMost Recent Write最近写入Most Recent w: "majority" write
t 0Primary applies Write 主应用写入0
Primary: Write 0
Secondary 1: Write prev
Secondary 2: Write prev
Primary: Write prev
Secondary 1: Write prev
Secondary 2: Write prev
t 1Secondary 1 applies write 0
Primary: Write 0
Secondary 1: Write 0
Secondary 2: Write prev
Primary: Write prev
Secondary 1: Write prev
Secondary 2: Write prev
t 2Secondary 2 applies write 0
Primary: Write 0
Secondary 1: Write 0
Secondary 2: Write 0
Primary: Write prev
Secondary 1: Write prev
Secondary 2: Write prev
t 3Primary is aware of successful replication to Secondary 1 and sends acknowledgement to client主服务器知道已成功复制到辅助服务器1
Primary: Write 0
Secondary 1: Write 0
Secondary 2: Write 0
Primary: Write 0
Secondary 1: Write prev
Secondary 2: Write prev
t 4Primary is aware of successful replication to Secondary 2主服务器知道已成功复制到辅助服务器2
Primary: Write 0
Secondary 1: Write 0
Secondary 2: Write 0
Primary: Write 0
Secondary 1: Write prev
Secondary 2: Write prev
t 5Secondary 1 receives notice (through regular replication mechanism) to update its snapshot of its most recent w: "majority" write次要1收到通知(通过常规复制机制)以更新其最新w: "majority"写入的快照
Primary: Write 0
Secondary 1: Write 0
Secondary 2: Write 0
Primary: Write 0
Secondary 1: Write 0
Secondary 2: Write prev
t 6Secondary 2 receives notice (through regular replication mechanism) to update its snapshot of its most recent w: "majority" write次要2收到通知(通过常规复制机制)以更新其最新w: "majority"写入的快照
Primary: Write 0
Secondary 1: Write 0
Secondary 2: Write 0
Primary: Write 0
Secondary 1: Write 0
Secondary 2: Write 0

Then, the following tables summarizes the state of the data that a read operation with "local" read concern would see at time T.然后,下表总结了在时间T具有"local"读取关注点的读取操作将看到的数据状态。

Timeline of a write operation to a three member replica set.
Read TargetTime TState of Data
PrimaryAfter t 0Data reflects Write 0.
Secondary 1Before t 1Data reflects Write prev
Secondary 1After t 1Data reflects Write 0
Secondary 2Before t 2Data reflects Write prev
Secondary 2After t 2Data reflects Write 0
←  Read ConcernRead Concern "available" →