简体   繁体   English

Cassandra写一致性级别ALL澄清

[英]Cassandra write consistency level ALL clarification

According to Datastax documentation for Cassandra : 根据Datastax 的Cassandra文档

"If the coordinator cannot write to enough replicas to meet the requested consistency level, it throws an Unavailable Exception and does not perform any writes." “如果协调器无法写入足够多的副本来满足请求的一致性级别,则它将引发Unavailable Exception并且不执行任何写入。”

Does this mean that while the write is in process, the data updated by the write will not be available to read requests? 这是否意味着在写入过程中,由写入更新的数据将不可用于读取请求? I mean it is possible that 4/5 nodes have successfully sent a SUCCESS to the coordinator, meaning that their data have been updated. 我的意思是可能4/5个节点已成功向协调器发送了SUCCESS,这意味着它们的数据已更新。 But the 5th one is yet to do the write. 但是第5个尚未完成。 Now if a read request comes in and goes to one of these 4 nodes, it will still show the old data until the coordinator recieves a confirmation from the 5th node and marks the new data valid? 现在,如果有读取请求进入并转到这4个节点之一,它将仍然显示旧数据,直到协调器从第5个节点收到确认并标记新数据有效为止?

If the coordinator knows that it cannot possibly achieve consistency before it attempts the write, then it will fail the request immediately before doing the write. 如果协调器在尝试写入之前知道它不可能达到一致性,则它将在执行写入之前立即使请求失败。 (This is described in the quote given) (在给出的报价中对此进行了说明)

However, if the coordinator believes that there are enough nodes to achieve its configured consistency level at the time of the attempt, it will start to send its data to its peers. 但是,如果协调器认为在尝试时有足够的节点达到其配置的一致性级别,它将开始向其对等方发送数据。 If one of the peers does not return a success, the request will fail and you will get into a state where the nodes that fail have the old data and the ones that passed have the new data. 如果对等方之一未返回成功,则请求将失败,您将进入一种状态,其中失败的节点具有旧数据,而通过的节点具有新数据。

If a read requests comes in, it will show the data it finds on the nodes it reaches no matter if it is old or new. 如果出现读取请求,则无论它是旧的还是新的,它都会显示在到达的节点上找到的数据。

Let us take your example to demonstrate. 让我们以您的榜样进行演示。

If you have 5 nodes and you have replication 3. This will mean that 3 of those 5 nodes will have the write that you have sent. 如果您有5个节点并且具有复制3。这意味着这5个节点中的3个将具有您已发送的写入。 However, one of the three nodes returned a failure to the coordinator. 但是,三个节点之一将故障返回给协调器。 Now if you read with consistency level ALL. 现在,如果您以一致性级别ALL阅读。 You will read all three nodes and will always get the new write (Latest timestamp always wins). 您将读取所有三个节点,并且将始终获得新的写入(最新时间戳始终为赢)。

However, if you read with consistency level ONE, there is a 1/3 chance you will get the old value. 但是,如果您以一致性级别ONE阅读,则有1/3的机会会得到旧值。

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

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