Hector在做incrementCounter后得到计数器值 [英] Hector to get the resulting counter value after doing incrementCounter

查看:156
本文介绍了Hector在做incrementCounter后得到计数器值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在进行以下操作来更新计数器的值,现在我们想知道是否有一种直接的方法可以立即返回更新的计数器值。

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);

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

推荐答案

在Cassandra thrift API中没有单一的incrementAndGet操作。

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

Cassandra中的计数器最终是一致且非原子的。需要Fragile ConsistencyLevel.ALL操作以获得保证更新计数器值,即执行一致性读取。 ConsistencyLevel.QUORUM是不够的(如计数器设计文档中指定的: https:/ /issues.apache.org/jira/secure/attachment/12459754/Partitionedcountersdesigndoc.pdf )。

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).

要实现外观一致的incrementAndGet方法,您可能需要先设置读取计数器值,然后发出增量突变和返回(读取值+ inc)。

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

例如,如果以前的计数器值为10到20(在不同的副本上)一个添加50,read-before-increment将返回60或70.并且后读取可能仍然返回10或20.

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.

这篇关于Hector在做incrementCounter后得到计数器值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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