mongodb写关注: all replica members dynamically?

标签 mongodb

是否可以将 WriteConcern 设置为类似 all 的内容,这意味着插入/更新仅在所有“当前功能”(操作时)时才会返回副本成员确认操作?

作为

  1. “多数”设置使一些成员下落不明。
  2. 如果我们指定一个数值,如果我们将 WriteConcern 设置为“成员总数”并且任何副本成员因任何原因关闭,则插入/更新可能会无限期暂停。
  3. 如果我们使用标签集,如官方文档中所述,我们仍然需要为每个标签提供一个数值,如果我们将数值指定为总成员数并且任何成员下降,结果将与第二点。

我们想到的是,如果有一个WriteConcern 的设置,它是动态插入/更新时的副本成员总数。

提前致谢!

最佳答案

Is it possible to set the WriteConcern to something like all which means the insert/update will only return when all "currently functional" (at time of the operation) replica members acknowledges the operation?

建议您的用例需要强一致性存在逻辑上的矛盾,除非这是不可能的。在某些情况下,例如复制滞后、维护或故障(以及后续恢复),您的一个或多个副本集辅助节点可能在线但落后于当前主节点。

如果您的用例需要强一致性,那么您应该始终从主节点而不是从节点读取,并使用多数/replica_safe 的写入关注点来确保数据已充分复制,以便在发生故障转移时实现高可用性。

默认 read preference是将读取定向到主数据库以保持一致性。 MongoDB 副本集中的辅助节点通常旨在支持高可用性而不是读取扩展(少数异常(exception),例如跨多个数据中心的分布)。更详细的解释见:Can I use more replica nodes to scale? .

the 'majority' setting leave some members unaccounted for.

在进行副本集选举时,多数写入关注点与选举主节点所需的多数一致。副本集election mechanics包括确保新的主节点与副本集中(参与选举的节点)中可用的最新操作保持同步。

if we specify a numeric value, the insert/update may suspend indefinitely if we set the WriteConcern as "total number of members" and any replica members go down for any reason.

这是预期的默认行为,但是有 wtimeout写入关注选项设置时间限制(以毫秒为单位),因此写入不会无限期地阻塞等待确认得到满足。

关于使用超时的注意事项非常重要,并且提供的结果更不确定:

wtimeout causes write operations to return with an error after the specified limit, even if the required write concern will eventually succeed. When these write operations return, MongoDB does not undo successful data modifications performed before the write concern exceeded the wtimeout time limit.

写关注超时与副本集成员的当前运行状况(即他们是在线还是离线并且可能能够确认写关注)或最终结果没有直接关系——这只是一个关于如何很长一段时间,您的应用程序将在返回之前等待响应。

if we use tag set, as outlined in official docs, we still need to supply a numeric value to each tag and if we specify the numeric value as the total members count and any member goes down, the result would be same as 2nd point.

正确。

关于mongodb写关注: all replica members dynamically?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29988095/

相关文章:

c# - 查询 mongodb 集合为动态

mongodb - 容器启动后运行命令

如果属性数组不包含对象,MongoDB 会查找文档

javascript - meteor.js & collection2 - 如何查询子模式

java - 如何在 Spring Data MongoDB 存储库中查询日期?

java - Spring应用程序中dao中的泛型类型

javascript - 是否有 Mongoose 方法来保存多个文档,但只有当全部成功时

mongodb - MongoDB 批处理操作的最大大小是多少?

c# - 如何使用 C# 驱动程序检查 MongoDB 中是否存在集合?

MongoDB 日志文件增长