Hector在执行incrementCounter之后获取结果计数器值

tom*_*tom 6 counter cassandra hector

我们正在执行以下操作来更新计数器的值,现在我们想知道是否有一种直接的方法来立即获取更新的计数器值.

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

Wil*_*ire 7

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

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

要实现看起来一致的incrementAndGet方法,您可能首先要读取计数器值,然后发出增量变异,然后返回(读取值+ inc).

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