Couchbase - 当节点重新联机时,节点上的旧文档会发生什么?

Couchbase - what happens to old documents on a node when it comes back online?

假设我有一个包含 2 个数据节点的 Couchbase 集群:1 和 2。

文档 X 在节点 1 上处于活动状态并在节点 2 上复制。

假设节点1宕机,文档X在节点2上被提升为'active'。节点1宕机了一段时间;同时,对文档 X 进行了大量更改。

一段时间后,节点 1 重新联机。请记住,文档 X 在节点 1 中是 'active'。

会发生什么?似乎文档 X 在两个节点上都处于活动状态。 Couchbase 可以自己处理这个冲突,还是我必须在我的应用程序代码中做任何事情来解决它?

这是通过 vBucket 级别的重新平衡处理的。

根据this blog post about rebalancing

When a client ... is sending requests to the cluster, it takes the key and hashes it against the list of vbuckets. It then looks at the map that it has to determine which server is active for that vbucket. If its map is correct, the server will accept the request... If the vbucket id that the client ... is sending to a server is not active on that server, it will respond with an error saying 'not my vbucket'. During a rebalance, if a client doesn't get updated in time, has some requests 'in flight' or somehow just misses the memo, the old node will respond with a 'not my vbucket' error to any requests after this point in time.

这是一篇旧博客 post,但它仍然适用。基本上不用担心节点重新上线时与旧文档冲突。

更深入一点,如果 vBucket 在节点 2 上被提升为活动状态,则意味着手动或自动发生了故障转移。当节点 1 恢复时,您必须重新添加该节点。如果您还没有重新平衡,您可以使用增量节点恢复将节点重新添加,集群将从它停止的地方赶上节点 1。另一种选择是添加该节点,就好像它是一个新节点一样,Couchbase 将删除并重新填充该节点。如需更详尽的解释,go read the newer 4.5 beta documentation。它适用于 4.0 和 4.1,其中大部分甚至 3.x 也是如此。

总之,长话短说...Couchbase 将负责在节点 1 停止的地方以一种或另一种方式捕获节点 1,因为如果该对象在节点 2 上更新而节点 1 已关闭,它将获得更新的版本。