Hector to get the resulting counter value after doing incrementCounter

房东的猫 提交于 2019-12-07 03:25:28

问题


We are doing the following to update the value of a counter, now we wonder if there is a straightforward way to get back the updated counter value immediately.

mutator.incrementCounter(rowid1, "cf1", "counter1", value);


回答1:


There's no single 'incrementAndGet' operation in Cassandra thrift API.

Counters in Cassandra are eventually consistent and non-atomic. Fragile ConsistencyLevel.ALL operation is required to get "guaranteed to be updated" counter value, i.e. perform consistent read. ConsistencyLevel.QUORUM is not sufficient (as specified in counters design document: https://issues.apache.org/jira/secure/attachment/12459754/Partitionedcountersdesigndoc.pdf).

To implement incrementAndGet method that looks consistent, you might want at first read counter value, then issue increment mutation, and return (read value + inc).

For example, if previous counter value is 10 to 20 (on different replicas), and one add 50 to it, read-before-increment will return either 60 or 70. And read-after-increment might still return 10 or 20.




回答2:


The only way to do it is query for it. There is no increment-then-read functionality available in Cassandra.



来源:https://stackoverflow.com/questions/9038530/hector-to-get-the-resulting-counter-value-after-doing-incrementcounter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!