Atomic Batches in Cassandra
Asked Answered
S

4

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?

Subchaser answered 26/3, 2014 at 14:30 Comment(2)
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.Kimberelykimberlee
I just published a post that explains the differences between single and multi partition batches, hopefully it helps to better understand batches in general: inoio.de/blog/2016/01/13/cassandra-to-batch-or-not-to-batchKimberelykimberlee
B
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

Blackguard answered 26/3, 2014 at 22:8 Comment(2)
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?Subchaser
That is what an Unlogged batch would do (hint). Logged batches do a lot more.Battery
B
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.

Battery answered 8/6, 2015 at 12:41 Comment(0)
M
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

Murrell answered 14/10, 2014 at 4:32 Comment(1)
You get isolation in the same partition, not between partitions.Battery
E
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

Enchain answered 26/3, 2014 at 18:55 Comment(1)
They are called logged batches, however some blogs/docs have called them atomic.Battery

© 2022 - 2024 — McMap. All rights reserved.