Cassandra中的Counter Vs Int列? [英] Counter Vs Int column in Cassandra?

查看:160
本文介绍了Cassandra中的Counter Vs Int列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Cassandra的新手。我无法理解在表中使用计数器的优势(如果非计数器列不是复合PRIMARY KEY的一部分,甚至在其他表中使用计数器的优势)?为什么我不使用Int类型的列,当我有x = x ++之类的语句时;

可以在Cassandra中使用Int Type的增量或减量吗?

I'm new in Cassandra. I can't understand what is the advantage of using counter in a table (or even in a different table if the non-counter columns are not part of the composite PRIMARY KEY)? Why we don't use a column with Int type, when I will have some statements like x=x++; what is the different between using int or counter?
Is that possible to use increments or decrements for Int Type in Cassandra at all?

推荐答案


为什么我们不使用Int类型的列,当我有一些语句时像x = x ++;使用int或counter有什么区别?

Why we don't use a column with Int type, when I will have some statements like x=x++; what is the different between using int or counter?

因为使用普通的Int列需要 read-before-write 锁定,例如 x = x ++

Because using a normal Int column would require read-before-write and lock for operations like x=x++

当您可以对同一值进行并发更新时,保证 x = x ++ 行为一致的唯一方法是:

Indeed, for a distributed database when you can have concurrent updates on the same value, the only way to guarantee consistent behaviour for x=x++ is:


  1. 锁定当前记录

  2. 读取x的当前值,将其递增1

  3. 写回x的新值

  4. 释放锁

  1. lock the current record
  2. read the current value of x, increment it by 1
  3. write back the new value of x
  4. release the lock

Counter 类型允许同时递增/递减值,而无需先写先读锁定

Counter type allows concurrent increment/decrement on the value without neither requiring read-before-write nor locking

这篇关于Cassandra中的Counter Vs Int列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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