为什么MongoDB的 write concern 不能指定全部节点?

项目中遇到一个需求:必须保证在写入后,数据都已同步到所有从节点才返回成功。MongoDB 架构使用了1主 2从 1仲裁,所以我设置了 w 为3,运作良好,符合预期。但是,当某个从节点宕机后,此时 data bearing 节点只有两个,使用 w = 3 会出现异常,需要手动改为 w = 2,等宕机的从节点重新连接后;又需要改为 w = 3。所以我在想,就像 w = majority 代表大多数 data bearing 节点,那么为什么没有 w = max 的代表所有 data bearing 节点呢?

这是在 stackoverflow 找到的讨论 => 地址

解答一:

There are numerous problems with this, I mean how do you judge the complete number of max up members while making sure you get all members of the set? What about dealing with down members?

解答二:

If your use case requires strong consistency then you should always read from the primary instead of secondaries, and use a write concern of majority / replica_safe to ensure data has replicated sufficiently for high availability in the event of failover.

解答三:

The default read preference is to direct reads to the primary for consistency. Secondaries in MongoDB replica sets are generally intended to support high availability rather than read scaling (with a few exceptions such as distribution across multiple data centres).

综上:从节点通常是用来做故障转移、保证高可用的,如果需要强一致性,那就只读Primary。

解答一我没理解,欢迎留言交流!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值