cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vladimir Yudovin <vla...@winguzone.com>
Subject Re: Inserting list data
Date Sat, 15 Oct 2016 04:44:51 GMT
Did you try the same quires with Java driver without using prepared statements?





Best regards, Vladimir Yudovin, 

Winguzone - Hosted Cloud Cassandra on Azure and SoftLayer.
Launch your cluster in minutes.






---- On Fri, 14 Oct 2016 15:13:38 -0400Aoi Kadoya &lt;cadyan.aoi@gmail.com&gt; wrote
----




Hi Vladimir, 

 

In fact I am having difficulty to reproduce this issue by cqlsh. 

I was reported this issue by one of our developers and he is using his 

client application that uses cassandra java driver 3.0.3. (we're using 

DSE5.0.1) 

 

&lt;here is how his application log look like&gt; 

 

app A: 

2016-10-11 13:28:23,014 [TRACE] [core.QueryLogger.NORMAL] [cluster1] 

[HOST1/IP1:9042] Query completed normally, took 5 ms: [8 bound values] 

INSERT INTO global.table_name 

("id","alert_to","alert_emails","created_by","created_date","alert_level","updated_by","updated_date")


VALUES (?,?,?,?,?,?,?,?); 

[id:25712, alert_to:[2], alert_emails:NULL, 

created_by:'service-worker:ec45afd2-c40a-44d9-a2a1-7416409be6e2', 

created_date:1476160103007, alert_level:2, updated_by:NULL, 

updated_date:NULL] 

 

app B: 

2016-10-11 13:28:23,014 [TRACE] [core.QueryLogger.NORMAL] [cluster1] 

[HOST2/IP2:9042] Query completed normally, took 6 ms: [8 bound values] 

INSERT INTO global.table_name 

("alert_to","alert_emails","created_date","id","created_by","updated_by","updated_date","alert_level")


VALUES (?,?,?,?,?,?,?,?); 

[alert_to:[1], alert_emails:NULL, created_date:1476160103007, 

id:25712, created_by:'service-worker:ec45afd2-c40a-44d9-a2a1-7416409be6e2', 

updated_by:NULL, updated_date:NULL, alert_level:1] 

 

&lt;and the data on cassandra&gt; 

&lt;TYPES&gt; 

 id bigint, 

 alert_emails list, 

 alert_level int, 

 alert_to list, 

 created_by text, 

 created_date timestamp, 

 updated_by text, 

 updated_date timestamp, 

 PRIMARY KEY (id) 

 

 

SELECT id, alert_level, alert_to FROM global.table_name WHERE id=25712; 

| id | alert_level | alert_to | 

| 25712 | 2 | [2, 1] | 

 

but when I threw the queries like below from cqlsh from different 

nodes at the same time in my testing environment, the data(alert_to) 

was just [1], which is expected behavior. 

 

on host 1 

cqlsh&gt; INSERT INTO global.table_name 

("id","alert_to","alert_emails","created_by","created_date","alert_level","updated_by","updated_date")


VALUES (25712,[2],NULL,'service-worker:ec45afd2-c40a-44d9-a2a1-7416409be6e2',1476160103007,2,NULL,NULL);


on host2 

cqlsh&gt; INSERT INTO global.table_name 

("alert_to","alert_emails","created_date","id","created_by","updated_by","updated_date","alert_level")


VALUES ([1],NULL,1476160103007,25712,'service-worker:ec45afd2-c40a-44d9-a2a1-7416409be6e2',NULL,NULL,1);


 

 

so I wonder if this is something wrong with java driver but I cannot 

figure out the way to break this down further. 

 

 

@Andrew 

we're not using UDT..but appreciate if you could share your case, too. 

 

Thanks, 

Aoi 

 

2016-10-13 11:26 GMT-07:00 Andrew Baker &lt;bakerag1@gmail.com&gt;: 

&gt; I saw evidence of this behavior, but when we created a test to try to make 

&gt; it happen it never did, we assumed it was UDT related and lost interest, 

&gt; since it didn't have a big impact. I will try to carve some time to look 

&gt; into this some more and let you know if I find anything. 

&gt; 

&gt; On Wed, Oct 12, 2016 at 9:24 PM Vladimir Yudovin &lt;vladyu@winguzone.com&gt;


&gt; wrote: 

&gt;&gt; 

&gt;&gt; The data is actually appended. not overwritten. 

&gt;&gt; Strange, can you send exactly operators? 

&gt;&gt; 

&gt;&gt; Here is example I do: 

&gt;&gt; CREATE KEYSPACE events WITH replication = {'class': 'SimpleStrategy', 

&gt;&gt; 'replication_factor': 1}; 

&gt;&gt; CREATE TABLE events.data (id int primary key, events list&lt;text&gt;);


&gt;&gt; INSERT INTO events.data (id, events) VALUES ( 0, ['a']); 

&gt;&gt; SELECT * FROM events.data ; 

&gt;&gt; id | events 

&gt;&gt; ----+-------- 

&gt;&gt; 0 | ['a'] 

&gt;&gt; 

&gt;&gt; (1 rows) 

&gt;&gt; 

&gt;&gt; INSERT INTO events.data (id, events) VALUES ( 0, ['b']); 

&gt;&gt; SELECT * FROM events.data ; 

&gt;&gt; id | events 

&gt;&gt; ----+-------- 

&gt;&gt; 0 | ['b'] 

&gt;&gt; 

&gt;&gt; (1 rows) 

&gt;&gt; 

&gt;&gt; As you see, 'a' was overwritten by 'b' 

&gt;&gt; 

&gt;&gt; 

&gt;&gt; Best regards, Vladimir Yudovin, 

&gt;&gt; Winguzone - Hosted Cloud Cassandra on Azure and SoftLayer. 

&gt;&gt; Launch your cluster in minutes. 

&gt;&gt; 

&gt;&gt; 

&gt;&gt; ---- On Wed, 12 Oct 2016 23:58:23 -0400Aoi Kadoya &lt;cadyan.aoi@gmail.com&gt;


&gt;&gt; wrote ---- 

&gt;&gt; 

&gt;&gt; yes, that's what I thought. but, when I use these forms, 

&gt;&gt; INSERT ... ['A'] 

&gt;&gt; INSERT ... ['B'] 

&gt;&gt; 

&gt;&gt; The data is actually appended. not overwritten. 

&gt;&gt; so I guess this is something unexpected? 

&gt;&gt; 

&gt;&gt; Thanks, 

&gt;&gt; Aoi 

&gt;&gt; 

&gt;&gt; 2016-10-12 20:55 GMT-07:00 Vladimir Yudovin &lt;vladyu@winguzone.com&gt;:


&gt;&gt; &gt; If you use form 

&gt;&gt; &gt; INSERT ... ['A'] 

&gt;&gt; &gt; INSERT ... ['B'] 

&gt;&gt; &gt; 

&gt;&gt; &gt; latest INSERT will overwrite first, because this insert the whole
list. 

&gt;&gt; &gt; It's 

&gt;&gt; &gt; better to use UPDATE like: 

&gt;&gt; &gt; UPDATE ... SET events = events + ['A'] 

&gt;&gt; &gt; UPDATE ... SET events = events + ['B'] 

&gt;&gt; &gt; These operations add new elements to the end of existing list. 

&gt;&gt; &gt; 

&gt;&gt; &gt; 

&gt;&gt; &gt; From here 

&gt;&gt; &gt; https://docs.datastax.com/en/cql/3.0/cql/cql_using/use_list_t.html


&gt;&gt; &gt; : 

&gt;&gt; &gt; 

&gt;&gt; &gt; These update operations are implemented internally without any 

&gt;&gt; &gt; read-before-write. Appending and prepending a new element to the
list 

&gt;&gt; &gt; writes 

&gt;&gt; &gt; only the new element. 

&gt;&gt; &gt; 

&gt;&gt; &gt; 

&gt;&gt; &gt; Best regards, Vladimir Yudovin, 

&gt;&gt; &gt; Winguzone - Hosted Cloud Cassandra on Azure and SoftLayer. 

&gt;&gt; &gt; Launch your cluster in minutes. 

&gt;&gt; &gt; 

&gt;&gt; &gt; 

&gt;&gt; &gt; ---- On Wed, 12 Oct 2016 17:39:46 -0400Aoi Kadoya &lt;cadyan.aoi@gmail.com&gt;


&gt;&gt; &gt; wrote ---- 

&gt;&gt; &gt; 

&gt;&gt; &gt; Hi, 

&gt;&gt; &gt; 

&gt;&gt; &gt; When inserting different data into a list type column from different


&gt;&gt; &gt; clients at the same time, is data supposed to be combined into one


&gt;&gt; &gt; list? 

&gt;&gt; &gt; 

&gt;&gt; &gt; For example, if these 2 queries were requested from clients at the


&gt;&gt; &gt; same timing, how events list should look like after? 

&gt;&gt; &gt; 

&gt;&gt; &gt; INSERT INTO cycling.upcoming_calendar (year, month, events) VALUES


&gt;&gt; &gt; (2015, 06, ['A']); 

&gt;&gt; &gt; INSERT INTO cycling.upcoming_calendar (year, month, events) VALUES


&gt;&gt; &gt; (2015, 06, ['B']); 

&gt;&gt; &gt; 

&gt;&gt; &gt; In my understanding, each operation should be treated as atomic,
which 

&gt;&gt; &gt; makes me think that even if client throw the queries at the same
time, 

&gt;&gt; &gt; cassandra would take them separately and the last insert would update


&gt;&gt; &gt; the events list. (= data should be either ['A'] or ['B']) 

&gt;&gt; &gt; 

&gt;&gt; &gt; In my environment, I found that some data was saved as like ['A',B']


&gt;&gt; &gt; in the case like above. 

&gt;&gt; &gt; Is this expected behavior of list data type? 

&gt;&gt; &gt; 

&gt;&gt; &gt; I am still new to cassandra and trying to make myself understood
how 

&gt;&gt; &gt; this happened. 

&gt;&gt; &gt; Appreciate if you could help me with figuring this out! 

&gt;&gt; &gt; 

&gt;&gt; &gt; Thanks, 

&gt;&gt; &gt; Aoi 

&gt;&gt; &gt; 

&gt;&gt; &gt; 







Mime
View raw message