CREATE TABLE usertopics ( key text,topic text,score counter,PRIMARY KEY (key,topic) )
我正在插入条目使用:
UPDATE usertopics SET score = score + ? WHERE key=? AND topic=?
这样如果密钥不存在,它将插入,如果它存在,它将更新.
我正在删除使用的条目:
Delete form usertopics where key in ?
但删除后,当我再次尝试更新时,它没有更新.它没有给出任何错误,但它也没有反映在db中.
当我截断表格时,它再次完美插入.我正在使用Datastax java驱动程序访问Cassandra.有什么建议?
解决方法
Counter removal is intrinsically limited. For instance,if you issue
very quickly the sequence “increment,remove,increment” it is
possible for the removal to be lost (if for some reason the remove
happens to be the last received messages). Hence,removal of counters
is provided for definitive removal only,that is when the deleted
counter is not increment afterwards. This holds for row deletion too:
if you delete a row of counters,incrementing any counter in that row
(that existed before the deletion) will result in an undetermined
behavior. Note that if you need to reset a counter,one option (that
is unfortunately not concurrent safe) could be to read its value and
add -value.
删除后,不能/不应使用具有相同密钥的计数器.请使用以下链接获取更多信息 –
https://docs.datastax.com/en/cql/3.1/cql/cql_using/use_counter_t.html
https://wiki.apache.org/cassandra/Counters