java - 如何修复 'Concurrent writes on cassandra lists issue when data in the lists is getting mixed' ..?

标签 java list cassandra

我编写了一个java程序来对我的cassandra数据库执行upsert操作,该数据库由一个具有多个列表的表组成,并使用我的java代码我试图同时写入许多这样的列表假设10个写入此刻,但是当我查看我的 cassandra 表时,列表中的值没有以同步方式存储,其中一些值从原始位置切换了位置,尽管每个值的时间戳都是正确的,但不知何故列表不是以正确的顺序表示。共享有助于识别问题的文件和示例代码。

String newInsertQuery1 =  "UPDATE events.generated_event SET attributes = ['100'] + attributes, channels = ['100'] + channels, " + "event_types = ['100'] + event_types, ip = ['100'] + ip, library_info = ['100'] + library_info, property_ids = ['100'] + property_ids," + "texts = ['100'] + texts, user_agent = ['100'] + user_agent WHERE profile_id = '1111' AND project_id = '5bbc83f4bf52016962b695da' AND bucket_id = 1555977600000"; 

String newInsertQuery2 =  "UPDATE events.generated_event SET attributes = ['300'] + attributes, channels = ['300'] + channels, " + "event_types = ['300'] + event_types, ip = ['300'] + ip, library_info = ['300'] + library_info, property_ids = ['300'] + property_ids," + "texts = ['300'] + texts, user_agent = ['300'] + user_agent WHERE profile_id = '1111' AND project_id = '5bbc83f4bf52016962b695da' AND bucket_id = 1555977600000";

String newInsertQuery3 =  "UPDATE events.generated_event SET attributes = ['400'] + attributes, channels = ['400'] + channels, " + "event_types = ['400'] + event_types, ip = ['400'] + ip, library_info = ['400'] + library_info, property_ids = ['400'] + property_ids," + "texts = ['400'] + texts, user_agent = ['400'] + user_agent WHERE profile_id = '1111' AND project_id = '5bbc83f4bf52016962b695da' AND bucket_id = 1555977600000";

类似地查询 4, 5, 6 ,7。

我创建了许多同时运行的线程,每个线程执行一个查询。

预期结果:

 profile_id   | 1111
 project_id   | 5bbc83f4bf52016962b695da
 bucket_id    | 1555977600000

 anonymous_id | 150698a7-5d02-f634-3c8d-4d7bf615f13e

 attributes   | ['300', '700', '400', '600', '500', '800', '00']

 channels     | ['300', '700', '400', '600', '500', '800', '00']

 event_types  | ['300', '700', '400', '600', '500', '800', '00']

 ip           | ['300', '700', '400', '600', '500', '800', '00']

 library_info | ['300', '700', '400', '600', '500', '800', '00']

 property_ids | ['300', '700', '400', '600', '500', '800', '00']

 texts        | ['300', '700', '400', '600', '500', '800', '00']

 timestamps   | null

 user_agent   | ['300', '700', '400', '600', '500', '800', '00']

实际结果:

 profile_id   | 1111
 project_id   | 5bbc83f4bf52016962b695da
 bucket_id    | 1555977600000
 anonymous_id | 150698a7-5d02-f634-3c8d-4d7bf615f13e

attributes   | ['300', '700', '500', '400', '800', '600', '00']

channels     | ['300', '700', '400', '600', '800', '500', '00']

event_types  | ['300', '700', '400', '600', '500', '800', '00']

ip           | ['300', '700', '400', '600', '500', '800', '00']

library_info | ['300', '700', '400', '600', '500', '800', '00']

property_ids | ['300', '700', '400', '600', '500', '800', '00']

texts        | ['300', '700', '400', '600', '800', '500', '00']

timestamps   | null

 user_agent   | ['300', '700', '400', '600', '500', '800', '00']

The image attached consist of the output of the sstabledump command and as you can see the tstamp are same for values say 800 in each row but when i perform a read on this table the values printed to me are not sorted out they are printed in the same order as written in sstabledump

最佳答案

如果您对不同线程发出的同一行使用多个查询,则无法保证更新将按特定顺序执行。

关于java - 如何修复 'Concurrent writes on cassandra lists issue when data in the lists is getting mixed' ..?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55920428/

相关文章:

java - 比较两个表并更新第二个表

Java HashMap 获取值(哪个值最多)

Java "if"语句

python - 使用索引列表从另一个列表中删除给我索引超出范围错误 - 为什么?

python - 在 Python 中基于一个属性合并两个嵌套列表

java - 如何使用 Spring Data Cassandra 将 java.util.Date 值插入到 Cassandra 日期类型列中?

java - HttpClient 4.2、基本身份验证和 AuthScope

c - 如何在 C 中将客户端的 IP 存储在数组中(套接字编程)

java - DefaultEntityManager 不允许我使用 <UUID, String> 的 ColumnFamily

cassandra - 使用 Spark 连接到 Cassandra