Reputation: 93
I figured that if i execute batch in Cassandra(using java driver) no matter where the update/insert/delete placed, it always execute in the order of, update, insert, delete. Like the code below, after i run it, the table is empty. How can i force cassandra to execute to my order?
PreparedStatement trybach = MyConnection
.getSession()
.prepare(
"BEGIN BATCH USING TIMESTAMP"
+ " INSERT INTO transaction_test.users(email,age,firstname,lastname) VALUES ('try',18,'fname','lname');"
+ " DELETE FROM transaction_test.users WHERE email ='try';"
+ " UPDATE transaction_test.users SET age= 13 WHERE email= 'try';"
+
"APPLY BATCH");
MyConnection.getSession().execute(trybach.bind());
Upvotes: 3
Views: 803
Reputation: 5249
Batching in Cassandra doesn't imply any particular order in which the batched statements are executed. In fact all statements will be executed using the same timestamp, just as if all statements have been executed concurrently at the same time. In your example the delete statement would be effective over the inserts/updates, since it would just mark the row as deleted using the same timestamp as the row creation time.
Since you're mentioning "transaction" in your example and seem to care about ordering of operations, I suggest you take a look at lightweight transactions for your use-case.
Upvotes: 6