Batch Operations

18 views
Skip to first unread message

ALearner

unread,
Sep 11, 2017, 1:12:39 AM9/11/17
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi All,

We are using Spring Data Cassandra with Datastax driver. We have the following requirement.

1> Perform batch operationz involving multiple tables
2> Would like to abort the batch if there is a change in a column value. e.g., if column version has a value of 2 in all the tables I want the batch to suceed otherwise I want it to fail
3> Inserts can go through if there is no existing rows already.


Would like to know if it is possible to achieve this functionality using Datastax driver + spring data. If yes, please point me to some resource around it which has examples.

Thanks

.

Andrew Tolbert

unread,
Sep 11, 2017, 11:01:22 AM9/11/17
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi,

You can do this with logged batches and lightweight transactions, but only for rows in a single partition in the same table.   The way that works is if the lightweight transaction succeeds, all batch operations are applied, otherwise they aren't.

Thanks,
Andy

ALearner

unread,
Sep 12, 2017, 4:12:12 AM9/12/17
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi,

Thanks for the reply. I think logged batches would provide Atomicity for multiple partitions as well(doc. reference). But my requirement is a bit different where I want to FAIL the batch when "certain conditions are NOT met", not based on any the error from Cassandra.

The requirement is more specific to Datastax driver with Spring Data. Any code snippet would greatly help.

Andrew Tolbert

unread,
Sep 12, 2017, 9:48:49 AM9/12/17
to DataStax Java Driver for Apache Cassandra User Mailing List
But my requirement is a bit different where I want to FAIL the batch when "certain conditions are NOT met", not based on any the error from Cassandra.

Requiring existing data to meet/not meet certain conditions is functionality that lightweight transactions provide (requiring existing data to meet/not meet certain conditions), but LWTs are not allowed when the batch has statements that apply across partitions/tables.   So while you do get support for atomic application of statements across partitions with logged batches, you can not do it based on some condition (using LWTs) if the statements in the batch apply across partitions/tables.

Thanks,
Andy
Reply all
Reply to author
Forward
0 new messages