我编写了一个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']
最佳答案
如果您对不同线程发出的同一行使用多个查询,则无法保证更新将按特定顺序执行。
关于java - 如何修复 'Concurrent writes on cassandra lists issue when data in the lists is getting mixed' ..?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55920428/