Maciej Miklas
Maciej Miklas

Reputation: 3330

Does Cassandra support parallel updates on Set data type?

This is my table:

CREATE KEYSPACE CqlDemo WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1};
CREATE TABLE CqlDemo.MyBooks (id UUID PRIMARY KEY,title TEXT, impcol set<int>);

Now I am inserting data by executing follwiing CQL queries:

update CqlDemo.mybooks set impcol=impcol+{0} where id=44a2054c-f98b-43a7-833d-0e1358fdaa82;
update CqlDemo.mybooks set impcol=impcol+{1} where id=44a2054c-f98b-43a7-833d-0e1358fdaa82;
update CqlDemo.mybooks set impcol=impcol+{2} where id=44a2054c-f98b-43a7-833d-0e1358fdaa82;
update CqlDemo.mybooks set impcol=impcol+{3} where id=44a2054c-f98b-43a7-833d-0e1358fdaa82;
update CqlDemo.mybooks set impcol=impcol+{4} where id=44a2054c-f98b-43a7-833d-0e1358fdaa82;
update CqlDemo.mybooks set impcol=impcol+{5} where id=44a2054c-f98b-43a7-833d-0e1358fdaa82;
update CqlDemo.mybooks set impcol=impcol+{6} where id=44a2054c-f98b-43a7-833d-0e1358fdaa82;
update CqlDemo.mybooks set impcol=impcol+{7} where id=44a2054c-f98b-43a7-833d-0e1358fdaa82;
update CqlDemo.mybooks set impcol=impcol+{8} where id=44a2054c-f98b-43a7-833d-0e1358fdaa82;
update CqlDemo.mybooks set impcol=impcol+{9} where id=44a2054c-f98b-43a7-833d-0e1358fdaa82;
update CqlDemo.mybooks set impcol=impcol+{10} where id=44a2054c-f98b-43a7-833d-0e1358fdaa82;
update CqlDemo.mybooks set impcol=impcol+{11} where id=44a2054c-f98b-43a7-833d-0e1358fdaa82;
update CqlDemo.mybooks set impcol=impcol+{12} where id=44a2054c-f98b-43a7-833d-0e1358fdaa82;
update CqlDemo.mybooks set impcol=impcol+{13} where id=44a2054c-f98b-43a7-833d-0e1358fdaa82;
update CqlDemo.mybooks set impcol=impcol+{14} where id=44a2054c-f98b-43a7-833d-0e1358fdaa82;

Those queres are being executed from java using datastax driver. When I execute them one after anoteher everythig is fine. But when I execute them in parallel, some inserts are just gone....

I am assuming threading bug in my code, but since I can't find it, I would like to know whether parallel updates on sets are somehow limited?

Here is my code: https://github.com/maciejmiklas/cyclop/blob/master/cyclop-webapp/src/main/java/org/cyclop/service/importer/impl/ParallelQueryImporter.java https://github.com/maciejmiklas/cyclop/blob/master/cyclop-webapp/src/main/java/org/cyclop/service/importer/impl/ImportWorker.java

Upvotes: 2

Views: 173

Answers (1)

ashic
ashic

Reputation: 6495

Cassandra collections are fetched and stored in their entirety. And cassandra does last write wins. Some of your updates are essentially getting overwritten by subsequent ones.

Upvotes: 1

Related Questions