4
votes

We have counter column family , something like that: create column family visits_counter_cf with key_validation_class =UTF8Type and comparator = 'CompositeType(LongType, LongType, UTF8Type)' and default_validation_class=CounterColumnType;

When we delete a row from this column family (we using Hector) in the CLI it looks deleted But then when we increment counters in the same row (the same rowkey) it continues increment the counters from the previous counter values (the values before deletion). Please help to understand this behavior,

1
What version of Cassandra?zznate
It's a bit old :-) 1.0.9user3021296
The same behavior is in CLI . When I increment a counter then delete the row and again increment the counter , the counter value is 2 but not 1 as expected..user3021296
We did the same thing and observed the same behaviour. The only thing that "fixed" it, i.e. allowed re-inserting the row was to truncate the table. Fortunately this was a test DB and not prod but at least we learned from this mistake :).kha

1 Answers

3
votes

There are a number of serious limitations to the current Cassandra counter implementation. One of them is that an increment on a deleted column (or column in a deleted row) is considered undefined behavior. From the Cassandra counters wiki page:

Counter removal is intrinsically limited. For instance, if you issue very quickly the sequence "increment, remove, increment" it is possible for the removal to be lost (if for some reason the remove happens to be the last received messages). Hence, removal of counters is provided for definitive removal only, that is when the deleted counter is not increment afterwards. This holds for row deletion too: if you delete a row of counters, incrementing any counter in that row (that existed before the deletion) will result in an undetermined behavior.

In short, you should not try to reuse a deleted row in a counter column family.