删除后 Cassandra 更新不工作

Cassandra UPDATE not working after deletion

我在 Cassandra 中使用宽行模式。我的table定义如下:

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 ?

但是删了之后想再更新的时候更新不了。它没有给出任何错误,但也没有反映在数据库中。

当我截断 table 时,它再次完美插入。我正在使用 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.

一旦删除,具有相同密钥的计数器cannot/should将无法使用。请使用以下链接获取更多信息 -

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