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"
和事务
"local"
and TransactionsYou 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写入三成员副本集:
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之后没有发生其他写入操作。
Most Recent w: "majority" write | |||
---|---|---|---|
t 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 | Primary: Write 0 Secondary 1: Write 0 Secondary 2: Write prev | Primary: Write prev Secondary 1: Write prev Secondary 2: Write prev | |
t 2 | Primary: Write 0 Secondary 1: Write 0 Secondary 2: Write 0 | Primary: Write prev Secondary 1: Write prev Secondary 2: Write prev | |
t 3 | Primary: Write 0 Secondary 1: Write 0 Secondary 2: Write 0 | Primary: Write 0 Secondary 1: Write prev Secondary 2: Write prev | |
t 4 | Primary: Write 0 Secondary 1: Write 0 Secondary 2: Write 0 | Primary: Write 0 Secondary 1: Write prev Secondary 2: Write prev | |
t 5 | 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 | 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
."local"
读取关注的读取操作在时间T
时会看到的数据状态。
Time T | ||
---|---|---|
Primary | After t 0 | |
Secondary 1 | Before t 1 | |
Secondary 1 | After t 1 | |
Secondary 2 | Before t 2 | |
Secondary 2 | After t 2 |