Should we use Cassandra NoSQL counter or LWT for auto incremental integer key generation?

后端 未结 1 1070
北荒
北荒 2021-01-24 06:24

We want to generated auto incremental integer key in Cassandra. This is trivial task in traditional databases but little complicated in Cassandra.

I have tried out Count

相关标签:
1条回答
  • 2021-01-24 06:37

    Starting with a Disclaimer, You most likely do not want an auto-incrementing integer key in C*. More likely a UUID or TimeUUID is what you want. But if you do happen to really need an auto incrementing value read on.

    State and Distributed Systems do not like to blend. Generally whenever you want to make 'really' sure of the state of your distributed system you have to check all replicas and thus sacrifice availability/partition tolerance. LWT use Paxos to allow check and set operations but to do this they require a quorum of nodes and are significantly slower than normal Cassandra operations. LWT should only be used in a small percentage of the operations used in your applications. As long as there is little contention for the counter variable and you don't need it for every write you should be ok.

    Counters in C* are a very different implementation. In older versions of C* they were slightly infamous for their ability to lose track of values. Their implementation has been rewritten for vastly improved stability but it would require careful planning on the application side to guarantee unique operations. You can imagine two clients both incrementing a counter simultaneously each thinking that they had received a unique value. Because of this I think you should use LWT if you really need to make sure of uniqueness.

    0 讨论(0)
提交回复
热议问题