我们应该使用Cassandra NoSQL计数器还是LWT来自动生成增量整数密钥? [英] Should we use Cassandra NoSQL counter or LWT for auto incremental integer key generation?

查看:100
本文介绍了我们应该使用Cassandra NoSQL计数器还是LWT来自动生成增量整数密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们想在Cassandra中生成自动增量整数密钥。在传统数据库中,这是一项微不足道的任务,但在Cassandra中却没有什么复杂的事情。

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

我已经尝试过可以使用

value=value+1

并尝试带有

UPDATE myTable SET value=newValue  IF value=oldValue.
(where newValue=oldValue+1 for auto increment)

强烈警告我计数器变量。我不确定为什么。能否请您帮助我了解以上两种方法的利弊?

I have been strongly warned against counter variables. I am not sure why though. Can you please help me understand pros and cons of above two approaches?

推荐答案

从免责声明开始,
可能不希望在C *中使用自动递增的整数键。您想要的是UUID或TimeUUID。但是,如果确实需要读取一个自动递增的值。

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.

状态和分布式系统不喜欢混合。通常,每当您要真正确定分布式系统的状态时,都必须检查所有副本,从而牺牲可用性/分区容限。 LWT使用Paxos允许检查和设置操作,但是要做到这一点,它们需要一定数量的节点,并且比正常的Cassandra操作要慢得多。 LWT仅应在应用程序中使用的操作的一小部分中使用。只要计数器变量没有什么争用,并且每次写入都不需要它,就可以了。

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.

C *中的计数器是非常不同的实现。在较旧的C *版本中,它们因无法跟踪值而臭名昭著。已经重写了它们的实现,以极大地提高了稳定性,但是这需要在应用程序端进行仔细计划以确保唯一的操作。您可以想象两个客户同时认为自己已经获得了唯一的价值而同时增加了一个计数器。因此,我认为如果您确实需要确保唯一性,则应该使用LWT。

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.

这篇关于我们应该使用Cassandra NoSQL计数器还是LWT来自动生成增量整数密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆