Cassandra 不保证原子行为,因此一个副本失败但其他副本确实保留更改的可能性很小。
是否有关于如何防御这种情况以及如何在发生这种情况时治愈它的信息? Cassandra 在这方面会自愈吗?
[更新]
我特别关注您向所有副本发送写入请求并且只有一个副本因写入错误而失败的情况。写入失败的节点仍然存在并且可以运行。根据 Cassandra 文档,写入请求将返回失败,即使其他两个(如果您的复制因子为 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更详细地解释了提示切换。
关于transactions - Cassandra 报告失败但只写了部分怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30017301/