"linearizable"
The query returns data that reflects all successful majority-acknowledged writes that completed prior to the start of the read operation. 查询返回的数据反映了在读取操作开始之前完成的所有成功的多数确认写入。The query may wait for concurrently executing writes to propagate to a majority of replica set members before returning results.查询可以在返回结果之前等待并发执行的写入传播到大多数副本集成员。
If a majority of your replica set members crash and restart after the read operation, documents returned by the read operation are durable if 如果大多数副本集成员在读取操作后崩溃并重新启动,则如果writeConcernMajorityJournalDefault
is set to the default state of true
.writeConcernMajorityJournalDefault
设置为默认状态true
,则读取操作返回的文档是持久的。
With 当writeConcernMajorityJournalDefault
set to false
, MongoDB does not wait for w: "majority"
writes to be written to the on-disk journal before acknowledging the writes. writeConcernMajorityJournalDefault
设置为false
时,MongoDB在确认写入之前不会等待w: "majority"
写入写入到磁盘日志。As such, 因此,"majority"
write operations could possibly roll back in the event of a transient loss (e.g. crash and restart) of a majority of nodes in a given replica set."majority"
写入操作可能会在给定副本集中的大多数节点发生瞬时丢失(如崩溃和重新启动)时回滚。
You can specify linearizable read concern for read operations on the 您可以仅为primary
only.primary
设备上的读取操作指定可线性化的读取关注点。
Linearizable read concern guarantees only apply if read operations specify a query filter that uniquely identifies a single document.仅当读取操作指定了唯一标识单个文档的查询筛选器时,线性化读取关注点保证才适用。
Always use 在大多数数据承载成员不可用的情况下,始终使用具有线性化读取关注点的maxTimeMS。maxTimeMS
with linearizable read concern in case a majority of data bearing members are unavailable. maxTimeMS
ensures that the operation does not block indefinitely and instead ensures that the operation returns an error if the read concern cannot be fulfilled.确保操作不会无限期阻塞,相反,如果无法满足读取要求,则确保操作返回错误。
Read concern 读关注点"linearizable"
is unavailable for use with causally consistent sessions."linearizable"
不可用于因果一致的会话。
You cannot use the 不能将$out
or the $merge
stage in conjunction with read concern "linearizable"
. $out
或$merge
阶段与读取关注点"linearizable"
结合使用。That is, if you specify 也就是说,如果为"linearizable"
read concern for db.collection.aggregate()
, you cannot include either stages in the pipeline.db.collection.aggregate()
指定"linearizable"
读取关注点,则不能在管道中包含任何一个阶段。
Combined with 与"majority"
write concern, "linearizable"
read concern enables multiple threads to perform reads and writes on a single document as if a single thread performed these operations in real time; that is, the corresponding schedule for these reads and writes is considered linearizable."majority"
写关注点相结合,"linearizable"
读关注点使多个线程能够对单个文档执行读写操作,就像单个线程实时执行这些操作一样;也就是说,这些读写的相应调度被认为是可线性化的。
Changed in version 3.6.在版本3.6中更改。
Starting in MongoDB 3.6, you can use causally consistent sessions to read your own writes, if the writes request acknowledgement.从MongoDB 3.6开始,如果写入请求确认,您可以使用因果一致的会话来读取自己的写入。
Prior to MongoDB 3.6, in order to read your own writes you must issue your write operation with 在MongoDB 3.6之前,为了读取您自己的写入操作,您必须使用{ w: "majority" }
write concern, and then issue your read operation with primary
read preference, and either "majority"
or "linearizable"
read concern.{ w: "majority" }
写入关注点发出写入操作,然后使用primary
读取首选项发出读取操作,以及"majority"
或"linearizable"
读取关注点。
Unlike 与"majority"
, "linearizable"
read concern confirms with secondary members that the read operation is reading from a primary that is capable of confirming writes with { w: "majority" }
write concern. "majority"
不同,"linearizable"
”读关注点通过二级成员确认读操作是从能够通过{ w: "majority" }
写关注点确认写的主成员读取。[1] As such, reads with linearizable read concern may be significantly slower than reads with 因此,具有线性化读取关注点的读取可能比具有"majority"
or "local"
read concerns."majority"
或"local"
读取关注点时的读取慢得多。
Always use 在大多数数据承载成员不可用的情况下,始终使用具有线性化读取关注点的maxTimeMS
with linearizable read concern in case a majority of data bearing members are unavailable. maxTimeMS
。maxTimeMS
ensures that the operation does not block indefinitely and instead ensures that the operation returns an error if the read concern cannot be fulfilled.确保操作不会无限期阻塞,相反,如果无法满足读取要求,则确保操作返回错误。
For example:例如:
db.restaurants.find( { _id: 5 } ).readConcern("linearizable").maxTimeMS(10000) db.runCommand( { find: "restaurants", filter: { _id: 5 }, readConcern: { level: "linearizable" }, maxTimeMS: 10000 } )
[1] | { w: "majority" } write concern. { w: "majority" } 写操作。{ w: "majority" } writes is the current primary, and the other node is a former primary that has not yet recognized its demotion, typically due to a network partition. { w: "majority" } 写入的节点是当前主节点,而另一个节点是尚未识别其降级的前主节点,通常是由于网络分区。primary , and new writes to the former primary will eventually roll back.primary 的客户端可能会观察到陈旧数据,尽管已请求primary 的读取首选项,而对前primary 进行的新写入最终将回滚。 |