Counter Vs Int column in Cassandra?

不羁的心 提交于 2019-11-30 04:38:51

问题


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?


回答1:


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?

Because using a normal Int column would require read-before-write and lock for operations like 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. 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 type allows concurrent increment/decrement on the value without neither requiring read-before-write nor locking



来源:https://stackoverflow.com/questions/35412377/counter-vs-int-column-in-cassandra

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