Re: Consistency when adding data to collections concurrently?

2016-11-13 Thread Ali Akhtar
Yeah, except I guess there's a minor debate left on whether it'd be more performant to store the labels in their own table, and do a read query each time when the parent item is fetched. Or if they should be kept as a set on the parent item and take the penalty when updating / deleting labels.

Re: Consistency when adding data to collections concurrently?

2016-11-13 Thread DuyHai Doan
So problem solved! On Sun, Nov 13, 2016 at 1:37 PM, Ali Akhtar wrote: > Yeah, I am using set (not set though) > > On Sun, Nov 13, 2016 at 5:36 PM, DuyHai Doan wrote: > >> Yes you'd have to know the UDT values since it's part of the primary key >> to

Re: Consistency when adding data to collections concurrently?

2016-11-13 Thread Ali Akhtar
Yeah, I am using set (not set though) On Sun, Nov 13, 2016 at 5:36 PM, DuyHai Doan wrote: > Yes you'd have to know the UDT values since it's part of the primary key > to query your data. > > If I were you I would stick to using a set and use UPDATE my_table > SET labels =

Re: Consistency when adding data to collections concurrently?

2016-11-13 Thread DuyHai Doan
Yes you'd have to know the UDT values since it's part of the primary key to query your data. If I were you I would stick to using a set and use UPDATE my_table SET labels = labels + ; It does work well with concurrent updates. On Sun, Nov 13, 2016 at 1:32 PM, Ali Akhtar

Re: Consistency when adding data to collections concurrently?

2016-11-13 Thread Ali Akhtar
But then how would you query it? You'd need to know all the values of the udt, right? On Sun, Nov 13, 2016 at 5:30 PM, DuyHai Doan wrote: > "Also can you make a UDT a clustered key?" --> yes if it's frozen > > On Sun, Nov 13, 2016 at 1:25 PM, Ali Akhtar

Re: Consistency when adding data to collections concurrently?

2016-11-13 Thread DuyHai Doan
"Also can you make a UDT a clustered key?" --> yes if it's frozen On Sun, Nov 13, 2016 at 1:25 PM, Ali Akhtar wrote: > If I wanted to get all values for an item, including its labels, how would > that be done in the above case? > > Also can you make a UDT a clustered key?

Re: Consistency when adding data to collections concurrently?

2016-11-13 Thread Ali Akhtar
If I wanted to get all values for an item, including its labels, how would that be done in the above case? Also can you make a UDT a clustered key? On Sun, Nov 13, 2016 at 4:33 AM, Manoj Khangaonkar wrote: > Hi, > > Instead of using a collection, consider making label a

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread Manoj Khangaonkar
Hi, Instead of using a collection, consider making label a clustered column. With this each request will essentially append a column (label) to the partition. To get all labels would be a simple query select label from table where partitionkey = "value". In general , read + update of a

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread DuyHai Doan
"doing mapper.save() will do an insert rather than an update? " --> Yes The java driver mapper has no update method. To do an update you need to use the Accessor and roll out your own update statement On Sat, Nov 12, 2016 at 5:37 PM, Ali Akhtar wrote: > Just to be clear,

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread Ali Akhtar
Just to be clear, doing mapper.save() will do an insert rather than an update? On Sat, Nov 12, 2016 at 9:36 PM, Andrew Tolbert wrote: > I believe you are correct that the implementation taking the Set is the > right one to use. > > On Sat, Nov 12, 2016 at 9:44 AM

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread Andrew Tolbert
I believe you are correct that the implementation taking the Set is the right one to use. On Sat, Nov 12, 2016 at 9:44 AM Ali Akhtar wrote: > Or it could even take Set as the first bound var: > > void addLabel(Set label, String id); > > > On Sat, Nov 12, 2016 at 8:41 PM,

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread Ali Akhtar
Or it could even take Set as the first bound var: void addLabel(Set label, String id); On Sat, Nov 12, 2016 at 8:41 PM, Ali Akhtar wrote: > Andrew, > > I was thinking about setting up an accessor with that query and a bound > variable ? which binds to the instance being

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread Ali Akhtar
Andrew, I was thinking about setting up an accessor with that query and a bound variable ? which binds to the instance being added, e.g: @Query("UPDATE my_table SET labels = labels + ? WHERE id = ?") void addLabel(Label label, String id); Will that work? On Sat, Nov 12, 2016 at 8:38 PM,

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread Andrew Tolbert
You can do it in a SimpleStatement assuming you provide the CQL exactly as you provided, but in a PreparedStatement it will not work because cql prohibits provide bind values in collection literals. For it to work you could provide a List of UDT values in a bound prepared statement, i.e.:

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread Ali Akhtar
Looks like the trick was to use [] around the udt value literal. Any way to do this using the java driver? On Sat, Nov 12, 2016 at 7:58 PM, Ali Akhtar wrote: > Changing the double quotes to single quotes gives: > > UPDATE my_table SET labels = labels + {id: 'foo'} where

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread Ali Akhtar
Changing the double quotes to single quotes gives: UPDATE my_table SET labels = labels + {id: 'foo'} where id = ''; InvalidRequest: Error from server: code=2200 [Invalid query] message="Invalid user type literal for labels of type list" On Sat, Nov 12, 2016 at 7:50 PM, Ali Akhtar

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread Ali Akhtar
The question is about appending to a set of frozen and how to do that while avoiding the race condition. If I run: UPDATE my_table SET labels = labels + {id: "foo"} where id = 'xx'; I get: SyntaxException: line 1:57 no viable alternative at input '}' (...= labels + {id: ["fo]o"}...) Here

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread Vladimir Yudovin
If I used consistency = ALL both when getting the record, and when saving the record, will that avoid the race condition? If I use consistency level = all, will that cause it to end up with [1,2]? No. Even if you have only one host it's possible that two threads first both read data and than

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread Ali Akhtar
The labels collection is of the type set , where label is a udt containing: id, name, description , all text fields. On Sat, Nov 12, 2016 at 5:54 PM, Ali Akhtar wrote: > The problem isn't just the update / insert though, right? Don't frozen > entities get

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread Ali Akhtar
The problem isn't just the update / insert though, right? Don't frozen entities get overwritten completely? So if I had [1] [2] being written as updates, won't each update overwrite the set completely, so i'll end up with either one of them instead of [1,2]? On Sat, Nov 12, 2016 at 5:50 PM,

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread DuyHai Doan
Maybe you should use my Achilles mapper, which does generates UPDATE statements on collections and not only INSERT Le 12 nov. 2016 13:08, "Ali Akhtar" a écrit : > I am using the Java Cassandra mapper for all of these cases, so my code > looks like this: > > Item myItem =

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread Ali Akhtar
I am using the Java Cassandra mapper for all of these cases, so my code looks like this: Item myItem = myaccessor.get( itemId ); Mapper mapper = mappingManager.create( Item.class ); myItem.labels.add( newLabel ); mapper.save( myItem ); On Sat, Nov 12, 2016 at 5:06 PM, Ali Akhtar

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread Ali Akhtar
Thanks DuyHai, I will switch to using a set. But I'm still not sure how to resolve the original question. - Original labels = [] - Request 1 arrives with label = 1, and request 2 arrives with label = 2 - Updates are sent to c* with labels = [1] and labels = [2] simultaneously. What will happen

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread DuyHai Doan
Don't use list, use set instead. If you need ordering of insertion, use a map where timeuuid is generated by the client to guarantee insertion order When setting a new value to a list, C* will do a read-delete-write internally e.g. read the current list, remove all its value (by a

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread Ali Akhtar
If I used consistency = ALL both when getting the record, and when saving the record, will that avoid the race condition? On Sat, Nov 12, 2016 at 4:26 PM, Ali Akhtar wrote: > I'm responding to a 3rd party API, so I have no control over sending the > labels together instead

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread Ali Akhtar
I'm responding to a 3rd party API, so I have no control over sending the labels together instead of one by one. In this case, the API will send them one by one. The list is actually of a list and not a text (I used text for simplification, apologies). In that case, will updates still

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread Oskar Kjellin
Could you not send both labels in one request? Race conditions should still be handled as Vladimir suggests. But in this specific case the client could send both as 1 request thus simplifying the solution. /Oskar > On 12 nov. 2016, at 12:05, Vladimir Yudovin wrote: > >

Re: Consistency when adding data to collections concurrently?

2016-11-12 Thread Vladimir Yudovin
Hi Ali, What can I do so I end up with [1, 2] instead of either [1] or [2] after both requests have been processed? Use UPDATE, not INSERT. Thus new labels will be added to list, without overwriting old ones. Also consider usage of SET instead of LIST to avoid duplicates. Best regards,

Consistency when adding data to collections concurrently?

2016-11-12 Thread Ali Akhtar
I have a table where each record contains a list of labels. I have an endpoint which responds to new labels being added to a record by the user. Consider the following scenario: - Record X, labels = [] - User selects 2 labels, clicks a button, and 2 http requests are generated. - The server