As per this <https://docs.datastax.com/en/cql/3.3/cql/cql_reference/batch_r.html> doc conditional batches can contain queries only belonging to that partition. On trying it in 3.6 I got this exception as expected: InvalidRequest: Error from server: code=2200 [Invalid query] message="Batch with conditions cannot span multiple partitions"
On trying single partition batch with multiple LWT statements cassandra accepted them at times and rejected the complete batch statement based on the other LWT. I mean in the below batch BEGIN BATCH Statement 1 IF SOME CONDITION; Statement 2 IF SOME CONDITION2; Statement 3; APPLY BATCH; LWT of Either of Statement 1/2 was being observed of batch to be successful or fail and as per this doc <https://docs.datastax.com/en/cql/3.3/cql/cql_reference/batch_r.html> "If one statement in a batch is a conditional update, the conditional logic must return true, or the entire batch fails." Thats what must be essentially happening and therefore having more than one lwt may not make a lot of sence. One query still remains though, can single partition batch considered to be isolated per replica. Say if there are 5 rows in a partition and we are updating all using lwt the clients should read either all of them old or all of them during batch update. Will be glad if someone can clarify the above doubt. On Tue, Sep 6, 2016 at 11:18 PM, Bhuvan Rawal <bhu1ra...@gmail.com> wrote: > Hi, > > We are working to solve on a multi threaded distributed design which in > which a thread reads current state from Cassandra (Single partition ~ 20 > Rows), does some computation and saves it back in. But it needs to be > ensured that in between reading and writing by that thread any other thread > should not have saved any operation on that partition. > > We have thought of a solution for the same - *having a write_time column* > in the schema and making it static. Every time the thread picks up a job > read will be performed with LOCAL_QUORUM. While writing into Cassandra > batch will contain a LWT (IF write_time is read time) otherwise read will > be performed and computation will be done again and so on. This will ensure > that while saving partition is in a state it was read from. > > In order to avoid race condition we need to ensure couple of things: > > 1. While saving data in a batch with a single partition (*Rows may be > Updates, Deletes, Inserts)* are they Isolated per replica node. (Not > necessarily on a cluster as a whole). Is there a possibility of client > reading partial rows? > > 2. If we do a LOCAL_QUORUM read and LOCAL_QUORUM writes in this case could > there a chance of inconsistency in this case (When LWT is being used in > batches). > > 3. Is it possible to use multiple LWT in a single Batch? In general how > does LWT performs with Batch and is Paxos acted on before batch execution? > > Can someone help us with this? > > Thanks & Regards, > Bhuvan > >