对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

读关注 (read concern) "available"

具有 "available" 读关注的查询从实例中返回数据,但不保证数据已写入到大多数副本集节点(即可能会回滚)。

  • For a sharded cluster, "available" read concern provides greater tolerance for partitions.

    Queries with the "available" read concern don't require a check to ensure that the correct shard received the query.

    In the event of network partitions, these queries route to the shard considered appropriate before the network partition occurred. They do not wait for consistency guarantees from servers that may be unavailable. If the shard was undergoing chunk migration, queries with "available" can return orphaned documents.

    警告

    mongos does not guarantee that queries with read concern "available" route to the correct shards. The shard that receives the query returns data, but this shard may not be the authoritative owner of the requested data.

    这可能会导致查询返回不正确或意想不到的结果。

  • For unsharded collections (including collections in a standalone deployment or a replica set deployment), "local" and "available" read concerns behave identically.

无论读关注级别如何,节点上的最新数据可能无法反映系统中数据的最新版本。

Read concern "available" is unavailable for use with causally consistent sessions and transactions.

考虑以下对三节点副本集执行 Write 0 写入操作的时间轴:

注意

为简单起见,该示例预设以下条件:

  • Write 0 之前的所有写入均已成功复制到所有成员。

  • Write prev 是 Write 0 前一次的写入操作。

  • Write 0 之后没有发生其他写入操作。

对一个三节点组成的副本集执行写入操作的时间轴
时间
事件
最新写入
最新 w: "majority" 写入

t 0

主节点应用 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 1

从节点 1 应用 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 2

从节点 2 应用 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 3

主节点知道已成功复制到从节点 1,并向客户端发送确认

Primary: Write 0
Secondary 1: Write 0
Secondary 2: Write 0

Primary: Write 0
Secondary 1: Write prev
Secondary 2: Write prev

t 4

主节点感知到数据已成功复制到从节点 2

Primary: Write 0
Secondary 1: Write 0
Secondary 2: Write 0

Primary: Write 0
Secondary 1: Write prev
Secondary 2: Write prev

t 5

从节点 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 6

从节点 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 "available" read concern would see at time T.

对一个三节点组成的副本集执行写入操作的时间轴。
读取目标
时间 T
数据状态

主节点

t 0之后

数据反映写入 0

从节点 1

t1 之前

数据反映为 Write prev 应用后的状态

从节点 1

在 t 1 之后

数据反映为 Write 0 应用后的状态

从节点 2

t 2 之前

数据反映为 Write prev 应用后的状态

从节点 2

在 t 2 之后

数据反映为 Write 0 应用后的状态

给本页内容打分