Apache Cassandra delete from counter

会有一股神秘感。 提交于 2019-11-29 13:14:26

Cassandra has some strict limits on deleting counters. You cannot really delete a counter and then use it again in any short period of time. From the Cassandra wiki:

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. Note that if you need to reset a counter, one option (that is unfortunately not concurrent safe) could be to read its value and add -value.

The solution to re-adding a deleted counter key is to purge all record of it from the table:

nodetool repair $table
cqlsh -c "ALTER TABLE $table WITH gc_grace_seconds=1;"
sleep 1
nodetool compact $table

As you can imagine, this is not practical in a real system and should probably be reserved for emergencies if an important counter is somehow accidentally deleted.

It is better to ensure that can never happen.

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