datastaxdatastax-enterprisecassandra-2.1cassandra-clispring-data-cassandra

Cassandra query execution sequencing vs Eventual consistency issue


I am confused with cassandra eventual constancy vs query sequencing, i have following questions

  1. If I send 2 queries in sequence (without turning on isIdempotent property). First query is to Delete record and second query is to create records. Is it possible that the query 2 executes before query one.

my java code will look like this

 public void foo(){
   delete(entity);//First delete a record
   create(entity); //Second create a record
}

another thing I am not specifying any timestamp in my query.

2) My second question is, Cassandra is eventually consistent. And if I send both the above queries in sequential order and it doesnt get replicated to all nodes, will those queries maintain the order when actually its getting replicated to all nodes?

I tried to look cassandra documentation , although it talks about query sequencing in batch operations, but it doesnt talk about query sequencing in non batch operation.

I am using cassandra 2.1


Solution

  • By default, in modern versions, we use client side timestamps. Check the driver documentation here:

    https://datastax.github.io/java-driver/manual/query_timestamps/

    Based on the timestamp, C* operates using LWW heuristics (last write wins) if the create has an earlier timestamp than the delete, a query won't return data. If the create has a newer timestamp, it will.

    If you need linearization, i.e. the guarantee that certain operations will be executed in sequence, you can use lightweight transactions based on paxos:

    http://www.datastax.com/dev/blog/lightweight-transactions-in-cassandra-2-0