Apache Cassandra 从计数器中删除 [英] Apache Cassandra delete from counter

查看:19
本文介绍了Apache Cassandra 从计数器中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个用于研究 Apache Cassandra 和 Java EE 6 的小型网络应用程序.Cassandra 版本为 1.1.6.

I'm developing a little web application for studying Apache Cassandra and Java EE 6. Cassandra version is 1.1.6.

有问题让我发疯...我创建了一个带计数器的表(使用 cqlsh v. 3.0.0)

Have a problem driving me mad... I created a table with a counter (using cqlsh v. 3.0.0)

CREATE TABLE test (
  author varchar PRIMARY KEY,
  tot counter
)

并以这种方式放置一些值:

and put some values this way:

update test set tot = tot +1 where author = 'myAuthor';

列族完美更新

author   | tot
----------+-----
myAuthor |   1

但是,如果您尝试删除该行然后再次更新(使用相同的键),则什么也不会发生!该表不再更新,我不知道为什么:在我看来,一旦您使用了密钥,您就不能再使用它了.我在 datasax 文档 (http://www.datastax.com/docs/1.1/references/cql/cql_lexicon) 中寻找线索,但没有找到解决方案.

BUT, if you try to delete this row and then update again (with the same key), then nothing happens! The table is no more updated and I can't figure why: it seems to me that once you used a key than you can't use it anymore. I looked for clues in datasax documentation (http://www.datastax.com/docs/1.1/references/cql/cql_lexicon) but didn't manage to find a solution.

有人可以帮我吗?提前致谢

Can someone help me? Thank in advance

推荐答案

Cassandra 对删除计数器有一些严格的限制.您无法真正删除一个计数器,然后在任何短时间内再次使用它.来自 Cassandra wiki:

Cassandra has some strict limits on deleting counters. You cannot really delete a counter and then use it again in any short period of time. From the Cassandra wiki:

反删除本质上是有限的.例如,如果您非常快速地发出序列增量,删除,增量",则删除可能会丢失(如果由于某种原因删除恰好是最后收到的消息).因此,计数器的移除仅用于最终移除,即当被删除的计数器之后不递增时.这也适用于行删除:如果您删除一行计数器,则增加该行中的任何计数器(删除之前存在的)将导致不确定的行为.请注意,如果您需要重置计数器,一个选项(不幸的是不是并发安全的)可能是读取它的值并添加 -value.

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.

这篇关于Apache Cassandra 从计数器中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆