微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

删除后,Cassandra UPDATE无法正常工作

我在Cassandra中使用了宽行模式.我的表定义如下:

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.有什么建议?

解决方法

来自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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐