Docs HomeMongoDB Manual

Read Concern 读取关注"available"

A query with read concern "available" 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).读取关注为"available"的查询从实例返回数据,但不能保证数据已写入大多数副本集成员(即可能被回滚)。

For a sharded cluster, "available" read concern provides greater tolerance for partitions since it does not wait to ensure consistency guarantees. 对于分片集群"available"读取关注为分区提供了更大的容忍度,因为它不需要等待以确保一致性保证。That is, read concern "available" does not contact the shard's primary nor the config servers for updated metadata. 也就是说,读取关注"available"不会联系分片的主服务器,也不会联系配置服务器以获取更新的元数据。However, this means that a query with "available" read concern may return orphaned documents if the shard is undergoing chunk migrations.然而,这意味着,如果分片正在进行块迁移,则具有"available"读取关注的查询可能会返回孤立文档

For unsharded collections (including collections in a standalone deployment or a replica set deployment), "local" and "available" read concerns behave identically.对于未排序的集合(包括独立部署或副本集部署中的集合),"local""available"读取关注的行为相同。

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.无论读取关注级别如何,节点上的最新数据都可能无法反映系统中数据的最新版本。

Tip

See also: 另请参阅:

orphanCleanupDelaySecs

Availability可利用性

Read concern "available" is unavailable for use with causally consistent sessions and transactions.读取关注"available"不可用于因果一致的会话和事务。

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 主要应用写入0Primary: 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 0Primary: 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 0Primary: 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主服务器知道已成功复制到辅助服务器2Primary: 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:“多数”写入的快照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:“多数”写入的快照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 "available" read concern would see at time T.然后,下表总结了具有"available"读取关注的读取操作在时间T时会看到的数据状态。

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