gpt4 book ai didi

Cassandra UPDATE 在删除后不起作用

转载 作者:行者123 更新时间:2023-12-05 00:57:07 26 4
gpt4 key购买 nike

我在 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 ?

但是删除后当我再次尝试更新时,它没有更新。它没有给出任何错误,但它也没有反射(reflect)在 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.



删除后,不能/不应使用具有相同 key 的计数器。请使用以下链接了解更多信息 -

https://docs.datastax.com/en/cql/3.1/cql/cql_using/use_counter_t.html
https://wiki.apache.org/cassandra/Counters

关于Cassandra UPDATE 在删除后不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34989827/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com