简体   繁体   English

MongoDB Oplog差异

[英]MongoDB Oplog Difference

Start with a MongoDB replica set with size 5, nodes A through E. A is the active primary and receives writes from the clients with a write guarantee of majority.从大小为 5 的 MongoDB 副本集开始,节点 A 到 E。A 是活动的主节点,并以多数写入保证接收来自客户端的写入。 Say A receives 1, 2, 3, 4. Under my current knowledge, this is a valid state for the replica set's oplogs, since the writes have at least been applied to the majority:假设 A 收到 1、2、3、4。根据我目前的知识,对于副本集的 oplog,这是一个有效的 state,因为写入至少已应用于大多数:

A 1 2 3 4
B 1 4
C 1 2
D 2 3
E 3 4

Now, A is lost.现在,A迷路了。

How do the remaining nodes handle the difference in oplogs, or is there something preventing this situation?其余节点如何处理 oplogs 的差异,或者有什么东西阻止了这种情况?

When guaranteeing a write of majority, does that also mean that the majority of the nodes have caught up with the primary's oplog, as in can non-guaranteed writes be delayed until after the guaranteed writes have been processed?当保证多数写入时,这是否也意味着大多数节点已经赶上了主节点的 oplog,例如非保证写入可以延迟到保证写入处理完之后? In other words, can oplogs ever have a slightly different order, and how does this impact elections?换句话说,oplog 的顺序是否可以稍有不同,这对选举有何影响?

Non-primary nodes tail the primary's oplog.非主节点尾随主节点的 oplog。 Meaning each of the non-primary nodes processes the writes in the order that they were applied to the primary.这意味着每个非主节点都按照它们应用于主节点的顺序处理写入。 Therefore these are not possible:因此,这些是不可能的:

B 1 4
D 2 3
E 3 4

The writes are not transfered from primary to non-primary nodes individually based on their write concern.写入不会根据它们的写入问题单独从主节点传输到非主节点。

A write concern W > 1 means that, after the primary has committed the write locally, it waits for W-1 other nodes to acknowledge the write by communicating their oplog position to the primary and having that position move past the write being waited for.写入关注 W > 1 意味着,在主节点在本地提交写入后,它等待 W-1 个其他节点通过将其 oplog position 传达给主节点并让 position 移过正在等待的写入来确认写入。 If the required number of nodes haven't acknowledged the write in the configured timeout (if any), you get write concern timeout error.如果所需数量的节点尚未在配置的超时(如果有)中确认写入,则会收到写入关注超时错误。

In order for 4 to be acknowledged by any of the nodes, they must have processed writes 1 through 3 previously.为了让任何节点确认 4,它们必须先前已处理写入 1 到 3。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM