mongodb两concern说明
程序员文章站
2022-03-01 19:06:33
...
在mongo3.2以后才可以设置read concern,write concern是很早就有了。这两个concern到底有什么用呢,或者说用默认的预设是不是就可以了。用默认的基本可以满足90以上的场景,另外10就是很严格的场景,比如说:要求数据严格强一致,或者数据高可用等等。
这里主要记录一下rw concern的默认值: read concern 默认是 local,可选值:local,majority,linearizable,下面是说明:
"local" Default. The query 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).
"majority" The query returns data that has been acknowledged by a majority of the replica set members. To use read concern level of "majority", you must start the mongod instances with the --enableMajorityReadConcern command line option (or the replication.enableMajorityReadConcern set to true if using a configuration file). replica sets must use WiredTiger storage engine and election protocol version 1.
默认的read concern level是local,也就是默认: 读到的数据不一定是大多数(半数以上)节点都有的,也可能是roll back的数据,也就是最新的,可能有脏数据.
write concern默认值:w:1,就是一个节点确认了,也就是primary写入成功就确定写入成功了。其他像 w: 0, w:2, 2:3,就是0个,2个,3个节点确定;还有一个就是w:majority,也是大多数写入成功才确认写成功。
上一篇: 使用Java创建第一个区块链
下一篇: 用java简单分析下比特币区块链