Rakesh Singh Rana
Rakesh Singh Rana

Reputation: 107

Cassandra Write Time out error and no rollback occured

I have one node with replication factor 1 and fire a batch statement query on that node ,cassandra writes the data but failed to acknowledge with in timeout limit . then it gives a write timout exception with following stacktrace .

failed `Exception in thread "main" com.datastax.driver.core.exceptions.WriteTimeoutException: Cassandra timeout during write query at consistency ONE (1 replica were required but only 0 acknowledged the write)
    at com.datastax.driver.core.exceptions.WriteTimeoutException.copy(WriteTimeoutException.java:54)
    at com.datastax.driver.core.ResultSetFuture.extractCauseFromExecutionException(ResultSetFuture.java:271)
    at com.datastax.driver.core.ResultSetFuture.getUninterruptibly(ResultSetFuture.java:187)
    at com.datastax.driver.core.Session.execute(Session.java:126)
    at jason.Stats.analyseLogMessages(Stats.java:91)
    at jason.Stats.main(Stats.java:48) 

then if you go back and check the table then you will find data has been written . So my question is , if cassandra gives write timout exception then it should rollback the changes . I mean i don't want to write to database if i am getting write timout exception ,is there any rollback strategy present for that particular scenario .

Upvotes: 0

Views: 654

Answers (2)

bechbd
bechbd

Reputation: 6341

Based on your description what you are expecting is that Cassandra supports ACID compliant transaction at least with regards to the A - Atomicity. Cassandra does not provide ACID-compliant transactions instead it relies on eventual consistency to provide a durable data store. Cassandra does provide Atomicity in as much as a single partition on a node is atomic by which I mean an entire row will either be written or not. However a write can still succeed on one or more replicas but after the timeout set by your client. In this case the client would receive an error but the data would be written. There is nothing that will rollback that transaction. Instead the data in the cluster will become consistent using the normal repair mechanisms.

My suggestion for you would be to:

  1. In the case of a timeout do a retry of the write query
  2. Investigate why you are getting a timeout error on a write with a CL=ONE. If this is a multi-DC sort of setup have you tried CL=LOCAL_ONE.

Some docs to read: https://docs.datastax.com/en/cassandra/2.1/cassandra/dml/dml_atomicity_c.html https://docs.datastax.com/en/cassandra/2.1/cassandra/operations/opsRepairNodesReadRepair.html

Upvotes: 2

RussS
RussS

Reputation: 16576

Cassandra does not have any notion of rollbacks. If a write times out that means that the write may have succeeded or may not have. This is why C* tries to focus users on idempotent data models and structures.

The only means of actually performing some kind of conditional write is via Light Weight Transactions which allow for some check and set operations.

Upvotes: 1

Related Questions