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

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

问题描述

我正在开发一个用于学习Apache Cassandra和Java EE 6的Web应用程序。
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:


计数器移除本质上受到限制。例如,如果您非常快地发出序列increment,remove,increment,则可能丢失删除(如果由于某种原因,删除恰好是最后接收的消息)。因此,提供计数器的移除仅用于确定的移除,即当删除的计数器之后不递增时。这也适用于行删除:如果删除一行计数器,增加该行中的任何计数器(在删除之前存在)将导致未确定的行为。注意,如果您需要重置计数器,一个选项(不幸的是并不安全)可能是读取其值和添加值。

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天全站免登陆