Column Counter Vs Int in Kassandra?

I am new to Kassandra. I canโ€™t understand what is the advantage of using a counter in a table (or even in another table if columns without counter elements are not part of a composite PRIMARY KEY)? Why don't we use a column with type Int when I have expressions such as x = x ++; What is the difference between usage or counter?
Can I use increments or decrements for Int Type in Cassandra?

+5
source share
1 answer

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

Since a regular Int column will require read-before-write and a lock for operations like x=x++

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

  • lock current record
  • read the current value of x, increase it by 1
  • write the new value of x
  • release the lock

The type of counter allows you to simultaneously increase / decrease the value without using read-before-write and blocking

+7
source

Source: https://habr.com/ru/post/1243058/


All Articles