6

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?

Aacini
  • 65,180
  • 12
  • 72
  • 108
Ananth
  • 971
  • 9
  • 23
  • Not sure if you're happy with the answers, as none is accepted until now. My question would be if you are referring to multi- or single-partition batches, because they're handled differently. – MartinGrotzke Dec 30 '15 at 11:33
  • 1
    I just published a post that explains the differences between single and multi partition batches, hopefully it helps to better understand batches in general: https://inoio.de/blog/2016/01/13/cassandra-to-batch-or-not-to-batch/ – MartinGrotzke Jan 13 '16 at 23:04

4 Answers4

3

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

Arya
  • 2,135
  • 15
  • 13
  • How about the case that there is a problem with the query and not the node. Say , for example, there is a null value in the query and the 40th query fails as it has a null value. Do you mean to say that the following batch will never be logged and the error will be caught in batch validation? – Ananth Mar 28 '14 at 07:13
  • That is what an Unlogged batch would do (hint). Logged batches do a lot more. – Christopher Batey Jun 08 '15 at 12:40
3

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.

1

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

mission.liao
  • 328
  • 5
  • 12
0

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

vivek mishra
  • 1,162
  • 8
  • 16