Cassandra 报告失败但只写了部分怎么办?

What to do if Cassandra reports failure but did a partial write?

Cassandra 不保证原子行为,因此一个副本失败但其他副本确实保留更改的可能性很小。

是否有任何信息可以防止这种情况发生,以及如果发生这种情况如何治愈? Cassandra 在这方面会自愈吗?

[更新]

我特别关注您向所有副本发送写入请求并且只有一个副本因写入错误而失败的情况。写入失败的节点仍然存在并且可以运行。根据 Cassandra 文档,写入请求将 return 失败,即使其他两个(如果您的复制因子为 3)成功。

根据本例中的文档,两个副本已更改,一个保持原始状态。有人指出,在这种情况下,它是一个不一致的状态,因为其他两个将无法回滚写入的任何更改。

那么问题就来了,如何才能抵御这种情况。

在 cassandra 中,这样的超时不被视为失败。请参阅 this blog post 描述 Cassandra 在写入时如何处理不同的条件:

Remember that for writes, a timeout is not a failure.

How can we say that since we don’t know what happened before the replica failed? The coordinator can force the results towards either the pre-update or post-update state. This is what Cassandra does with hinted handoff.

...the coordinator stores the update locally, and will re-send it to the failed replica when it recovers, thus forcing it to the post-update state that the client wanted originally.

因此,为了回答您的问题,是的,cassandra 将使用提示切换进行自我修复,并且当该过程失败时(即 max_hint_window_in_ms 在副本联机之前超出),修复应该使事情进入一致状态。这是建议 运行 定期维修的原因之一。

This article 更详细地解释了提示切换。