2
votes

After watching Cassandra DS220 videos, I was passing a quiz and I met a statement that is actually true about Cassandra writes:

Writes that do not meet the consistency requirements are not rolled back

This is not what I actually expected, so I have some questions:

1) Can such writes even happen? I think they can if a node or two failed in the middle. Otherwise C* would need a two-phase commit
2) What will happen to the written value later? I know from C* documentation how hinted handoff will work:

When the cluster cannot meet the consistency level specified by the client, Cassandra does not store a hint.

But what will read repair do? For example if the old value is A and the new value is B, will read repair discard B, or will A be overwritten with B?
3) What will reads return if I read with QUORUM level and one of the nodes contains B (which was not completely written to meet the consistency level) ?

2

2 Answers

2
votes

When you are using anything higher than consistency level ONE and if you fail to meet the consistency requirements writes are not discarded but preserved on the nodes that did manage to write. There are two mechanisms that solve this issue. First one is repair and it compares Merkle trees of replica nodes as part of the anti-entropy process. Second one is read repair which triggers at a defined percentage of reads and does a similar thing: compares data from all replicas and updates where needed. If you use QUORUM for reads there is a higher chance that you will get the latest data if you are having issues writing to the database but its still not 100% reliable.

0
votes

The consistency level of a write request affects whether hints are written and a write request subsequently fails. If the cluster consists of two nodes, A and B, with a replication factor of 1, each row is stored on only one node. Suppose node A is down when a row K is written to it with a consistency level of ONE. In this case, the consistency level specified cannot be met, and since node A is the coordinator, it cannot store a hint. Node B cannot write the data, because it has not received the data as the coordinator nor has a hint been stored. The coordinator checks the number of replicas that are up and will not attempt to write the hint if the consistency level specified by a client cannot be met. A hinted handoff failure occurs and will return a UnavailableException exception. The write request fails and the hint is not written.

For more info refer here