Checking CQL INSERT/DELETE statement execution status?

988 views
Skip to first unread message

marko

unread,
Jan 25, 2014, 9:13:51 AM1/25/14
to java-dri...@lists.datastax.com
How do I check the execution status of INSERT or DELETE statements?

For example if I execute the following statement:

ResultSetFuture rsf = Session.executeAsync("DELETE FROM event WHERE id = 123");

I've tried examining both the ResultSetFuture as well as the ResultSet, but haven't figured out how to get data about whether the requested row was found and deleted.

Also, how do I determine whether an INSERT statement has succeeded?
Is it just that no exception gets thrown?

marko

Sylvain Lebresne

unread,
Jan 27, 2014, 3:52:19 AM1/27/14
to java-dri...@lists.datastax.com
On Sat, Jan 25, 2014 at 3:13 PM, marko <marko....@gmail.com> wrote:
How do I check the execution status of INSERT or DELETE statements?

You can't, in general. An important property of Cassandra to remember is that writes in C* (a delete being a write here in particular) do not incur a read internally. Which means that writes are simply "pushed" to the storage engine without any check whatsoever of whether the write actually overwrite/delete something or not. This means in particular that INSERT and UPDATE in CQL differs from their SQL counterparts in that both of them are basically equivalent and are "upsert". And insert will not fail even if the row exists, it will simply update it, and and update will not fail if the row doesn't exist, it will insert it (and there is no way to know if those happened or not).

Not that I said "in general" above because if you really need to say 'insert only if the row doesn't exists', you can use 'IF' conditions starting in Cassandra 2.0. That being said, doing so has a hefty consequence on performance and should generally be avoid when possible (see http://www.datastax.com/dev/blog/lightweight-transactions-in-cassandra-2-0 for more details about those). Using 'IF' conditions all the time would typically be wrong.

--
Sylvain
Reply all
Reply to author
Forward
0 new messages