Does Cassandra write to a node(which is up) even if Consistency cannot be met?

前端 未结 3 1060
故里飘歌
故里飘歌 2021-01-14 11:21

The below statement from Cassandra documentation is the reason for my doubt.

For example, if using a write consistency level of QUORUM with a replication factor of 3

相关标签:
3条回答
  • 2021-01-14 12:05

    I got it. Cassandra will not even attempt to write if it knows that consistency cannot be met. If consistency CAN be met, but does not have enough replicas to satisfy replication factor, then Cassandra would write to currently available replicas and gives a success message. Later when the replica is up again, it will write to other replica.

    For e.g. If Replication factor is 3 , 1 of 3 nodes are down, then if I write with a Consistency of 2, the write will succeed. But if Replication factor is 2 and 1 of 2 nodes are down , then if I write with a Consistency of 2, Cassandra will not even write to that single node which is available.

    What is mentioned in the documentation is a case where while write was initiated when the consistency can be met. But in between, one node went down and couldn't complete the write, whereas write succeeded in other node. Since consistency cannot be met, client would get a failure message. The record which was written to a single node would be removed later during node repair or compaction.

    0 讨论(0)
  • 2021-01-14 12:07

    Consistency in Cassandra can (is?) be defined at statement level. That means you specify on a particular query, what level of consistency you need.

    This will imply that if the consistency level is not met, the statement above has not met consistency requirements.

    There is no rollback in Cassandra. What you have in Cassandra is Eventual consistency. That means your statement might be a success in future if not immediately. When a replica node comes a live, the cluster (aka the Cassandra's fault tolerance) will take care of writing to the replica node.

    So, if your statement is failed, it might be succeeded in future. This is in contrary to the RDBMS world, where an uncommitted transaction is rolled back as if nothing has happened.

    Update: I stand corrected. Thanks Arun.

    From:

    http://docs.datastax.com/en/cassandra/2.0/cassandra/dml/dml_about_hh_c.html

    During a write operation, when hinted handoff is enabled and consistency can be met, the coordinator stores a hint about dead replicas in the local system.hints table under either of these conditions:

    So it's still not rollback. Nodes know the current cluster state and doesn't initiate the write if consistency cannot be met.

    0 讨论(0)
  • 2021-01-14 12:19

    At driver level, you get an exception.

    On the nodes that the write succeeded, the data is actually written and it is going to be eventually rolled back.

    In a normal situation, you can consider that the data was not written to any of the nodes.

    From the documentation:

    If the write fails on one of the nodes but succeeds on the other, Cassandra reports a failure to replicate the write on that node. However, the replicated write that succeeds on the other node is not automatically rolled back.

    0 讨论(0)
提交回复
热议问题