Write error "Cassandra timeout during write query at consistency SERIAL (2 replica were required but only 1 acknowledged the write)" if I use IF NOT EXISTS condition for INSERT

4,878 views
Skip to first unread message

a babula

unread,
Dec 19, 2016, 3:37:03 AM12/19/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi All,

 I am new to Cassandra. Here I am facing some issue for INSERT statement. If I use "IF NOT EXISTS" condition to avoid duplicate rows then good number of write queries fail with error  "Cassandra timeout during write query at consistency SERIAL (2 replica were required but only 1 acknowledged the write)".

If I remove the IF NOT EXISTS condition from INSERT then all write queries pass but there is a chance of getting overwritten. So is there any option to fix this write failure with this IF NOT EXISTS condition or is there any other option to avoid duplicate rows without using this IF NOT EXISTS condition .

Alex Popescu

unread,
Dec 23, 2016, 11:25:03 PM12/23/16
to java-dri...@lists.datastax.com
In case you are not familiar with the differences between lightweight transactions and normal write, I'd suggest reading at least this post http://www.datastax.com/dev/blog/lightweight-transactions-in-cassandra-2-0

--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-user+unsubscribe@lists.datastax.com.



--
Bests,

Alex Popescu | @al3xandru
Director Product Management
Development Solutions





a babula

unread,
Jan 2, 2017, 3:05:44 AM1/2/17
to DataStax Java Driver for Apache Cassandra User Mailing List
Alex,

I had already gone through the post and again went through after seeing your post but still I am not clear how to fix the Cassandra Timeout issue.

On Saturday, December 24, 2016 at 9:55:03 AM UTC+5:30, Alex Popescu wrote:
In case you are not familiar with the differences between lightweight transactions and normal write, I'd suggest reading at least this post http://www.datastax.com/dev/blog/lightweight-transactions-in-cassandra-2-0
On Mon, Dec 19, 2016 at 12:37 AM, a babula <babu...@gmail.com> wrote:
Hi All,

 I am new to Cassandra. Here I am facing some issue for INSERT statement. If I use "IF NOT EXISTS" condition to avoid duplicate rows then good number of write queries fail with error  "Cassandra timeout during write query at consistency SERIAL (2 replica were required but only 1 acknowledged the write)".

If I remove the IF NOT EXISTS condition from INSERT then all write queries pass but there is a chance of getting overwritten. So is there any option to fix this write failure with this IF NOT EXISTS condition or is there any other option to avoid duplicate rows without using this IF NOT EXISTS condition .

--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.

Igor Zubchenok

unread,
Aug 14, 2017, 8:25:42 PM8/14/17
to DataStax Java Driver for Apache Cassandra User Mailing List, al...@datastax.com
I have the same issue, and the post does not actually give an answer on the timeout issue.


On Saturday, 24 December 2016 07:25:03 UTC+3, Alex Popescu wrote:
In case you are not familiar with the differences between lightweight transactions and normal write, I'd suggest reading at least this post http://www.datastax.com/dev/blog/lightweight-transactions-in-cassandra-2-0
On Mon, Dec 19, 2016 at 12:37 AM, a babula <babu...@gmail.com> wrote:
Hi All,

 I am new to Cassandra. Here I am facing some issue for INSERT statement. If I use "IF NOT EXISTS" condition to avoid duplicate rows then good number of write queries fail with error  "Cassandra timeout during write query at consistency SERIAL (2 replica were required but only 1 acknowledged the write)".

If I remove the IF NOT EXISTS condition from INSERT then all write queries pass but there is a chance of getting overwritten. So is there any option to fix this write failure with this IF NOT EXISTS condition or is there any other option to avoid duplicate rows without using this IF NOT EXISTS condition .

--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.

Andrew Tolbert

unread,
Aug 15, 2017, 3:36:34 PM8/15/17
to DataStax Java Driver for Apache Cassandra User Mailing List, al...@datastax.com
Hi Igor,

When you use "IF NOT EXISTS"/ "IF EXISTS" cassandra uses lightweight transactions, as outlined in the aforementioned blog post that Alex linked.  

Essentially, to ensure the 'once at a time' nature of lightweight transactions, more work and coordination needs to be done between C* nodes.  Because of this, the likelihood of timeouts is more possible and in general operations may be slower.  For these kinds of timeouts, the threshold is governed by cas_contention_timeout_in_ms.

When you have a timeout at a SERIAL consistency level, this indicates that the coordination required for LWTs timed out, which would not happen when not using lightweight transactions.   That said, you can and likely still will get write timeouts with non-LWTs (they will happen at non-serial consistency levels). 

In the event of a timeout (LWT or not), you should come up with a strategy that meets the requirements of your application.  Depending on your requirements, it may be adequate to simply present an error to the user.  It may be appropriate to retry the operation and see if the transaction was applied (ResultSet.wasApplied indicates this) or to read the current data and make a decision at that point.

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