Atomic Batches in Cassandra

こ雲淡風輕ζ 提交于 2019-12-04 23:09:17

问题


What do you mean by Batch Statements are atomic in cassandra? Docs are a bit confusing in nature to be precise. Does it mean that queries are atomic across nodes in cluster?

Say,for example, i have a batch with 100 queries. If the 40th query in batch fails, what happens to the 39 queries executed in the batch?

I understand that there is a batchlog created under the hood and it will take care of the consistency for partial batches. Does it remove the rest of the 39 entries and provide the required atomic nature of batch queries.

In MYSQL, we set autocommit to false and hence we can rollback. Does cassandra rollback in those cases?


回答1:


The atomicity is co-ordinator based. This means that when you make an atomic batch mutation, it will go to one co-ordinator. If one of the mutations in your batches, 40 in your example, fails because the replica responsible for it is dead, the coordinator will write a hint for that replica and will deliver it when the dead node it back up.

However, there is one scenario in which you will end up with half applied mutations: if the co-ordinator itself has issues.

To learn more about atomic batches read this: http://www.datastax.com/dev/blog/atomic-batches-in-cassandra-1-2




回答2:


They are actually called Logged batches not Atomic batches. You get more than just hints (which you'd get for any write) you also get the batch replicated to 2 other nodes before the coordinator starts to do the writes.

I wrote a blog on this a while ago: http://christopher-batey.blogspot.co.uk/2015/03/cassandra-anti-pattern-cassandra-logged.html

For your specific question "Does it remove the rest of the 39 entries and provide the required atomic nature of batch queries"

No - Casssandra has no notion of rollback. The batch log replicas will keep retrying the query until they all succeed.




回答3:


Eventually Consistent is the major idea in C*, and they design batch in this same way. Different from transactions in SQL world, batches are 'replayed' instead of rollback when failure occurs.

This difference of design is reasonable, because in C*, addition is cheaper than deletion.

One thing needs to note is isolation is not permitted in C*. That is, other clients may still read partially updated value.

The feature discussion page of batch in C* https://issues.apache.org/jira/browse/CASSANDRA-4285




回答4:


atomic batches should be like All or nothing. I don't think so it should replay partial log only, as it doesn't go with atomic batch definition.

-Vivek



来源:https://stackoverflow.com/questions/22664129/atomic-batches-in-cassandra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!