Cassandra:生成唯一ID? [英] Cassandra: Generate a unique ID?

查看:338
本文介绍了Cassandra:生成唯一ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个分布式数据库。我想在列系列主键的唯一ID标签cassandrarel =tag> cassandra



我阅读了一些关于使用Java执行此操作的文章 UUID ,但似乎有一个碰撞的概率(即使它很低)。



我想知道是否有一种方法可以根据时间生成一个唯一的ID?

解决方案

您可以使用 TimeUUID 键入Cassandra, em> Type 1 UUID 。这使用时间和创建者的MAC地址和序列号。如果正确地生成序列号,则可以用零冲突来完成。 TimeUUIDs 的主要优点是ID可以按时间排序。有关详情,请参见 http://wiki.apache.org/cassandra/TimeBaseUUIDNotes



但是,时间排序不太可能对行键有用,因为当使用散列分区器时排序是无用的。而且生成唯一ID的复杂性可能是错误的来源。 Cassandra还通过使用 UUID 类型支持<4>类型4 UUID 。这些只是随机位。存在碰撞概率,但是碰撞概率(假设在Java中生成的不相关的随机数源)非常低 - 如果您在100年中创建了10亿秒,则一次碰撞的概率大约为50% 。 (有关详情,请参阅 http://en.wikipedia.org/wiki/Universally_unique_identifier#Random_UUID_probability_of_duplicates )。 p>

I'm working on a distributed data base. I'm trying to generate a unique ID that will serve as a column family primary key in .

I read some articles about doing this with Java using UUID but it seems like there is a probability for collision (even if it's very low).

I wonder if there is a way to generate a unique ID based on time maybe?

解决方案

You can use TimeUUID type in Cassandra, which creates a Type 1 UUID. This uses time and the creator's MAC address and a sequence number. If the sequence number is generated correctly this can be done with zero collisions. The main advantage of TimeUUIDs is that the IDs can be time ordered. See http://wiki.apache.org/cassandra/TimeBaseUUIDNotes for more info.

However, the time ordering is unlikely to be useful for row keys, since the ordering is useless when using a hash partitioner. And also the complexity of generating a unique ID could be a source of bugs. Cassandra also supports Type 4 UUIDs by using the UUID type. These are just random bits. There is a collision probability, but the collision probability (assuming uncorrelated random number sources, which it will be if you generate in Java) is extremely low - if you created 1 billion a second for 100 years the probability of one collision is about 50%. (See http://en.wikipedia.org/wiki/Universally_unique_identifier#Random_UUID_probability_of_duplicates for more details.)

这篇关于Cassandra:生成唯一ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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