Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Atomic Batches in Cassandra

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?

like image 642
Ananth Avatar asked Mar 26 '14 14:03

Ananth


3 Answers

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

like image 181
Arya Avatar answered Nov 11 '22 12:11

Arya


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.

like image 3
Christopher Batey Avatar answered Nov 11 '22 14:11

Christopher Batey


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

like image 1
mission.liao Avatar answered Nov 11 '22 14:11

mission.liao