You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Roland Hänel <ro...@haenel.me> on 2010/04/26 22:30:31 UTC
How to generate 'unique' identifiers for use in Cassandra
Typically, in the SQL world we use things like AUTO_INCREMENT columns that
let us create a unique key automatically if a row is inserted into a table.
What do you guys usually do to create identifiers for use in Cassandra?
Do we only rely on "currentTimeMills() + random()" to create something that
is 'unique enough' (but theoretically not fail-safe)? Or are some people
here using systems like ZooKeeper for this purpose?
-Roland
Re: How to generate 'unique' identifiers for use in Cassandra
Posted by Shuge Lee <sh...@gmail.com>.
import uuid
unique_key = uuid.uuid4()
if you using Python.
2010/4/28 Mark Robson <ma...@gmail.com>
> 2010/4/26 Roland Hänel <ro...@haenel.me>:
>> > Typically, in the SQL world we use things like AUTO_INCREMENT columns
>> that
>> > let us create a unique key automatically if a row is inserted into a
>> table.
>>
>
> auto_increment is an antipattern; it adds an extra key which you don't need
> (usually). If your data has a natural candidate key, use that. If not, add
> extra parts until you have a unique key.
>
> If you are using OrderPreservingParitioner, it is really important to use
> keys which can give you a lexically sortable range to scan when you need to
> find them, so that you can use get_range_slice etc.
>
> There are other approaches however - in some cases it may be possible to
> use columns instead of rows there. But you'd still need keys for the
> columns.
>
> A straightforward way of generating unique IDs for your objects is to add
> an incrementing ID (managed locally) to the host name of the (client) node
> where they were generated. But this is probably not helpful in most cases.
>
> Mark
>
--
Shuge Lee | Lee Li | 李蠡
Re: How to generate 'unique' identifiers for use in Cassandra
Posted by Mark Robson <ma...@gmail.com>.
>
> 2010/4/26 Roland Hänel <ro...@haenel.me>:
> > Typically, in the SQL world we use things like AUTO_INCREMENT columns
> that
> > let us create a unique key automatically if a row is inserted into a
> table.
>
auto_increment is an antipattern; it adds an extra key which you don't need
(usually). If your data has a natural candidate key, use that. If not, add
extra parts until you have a unique key.
If you are using OrderPreservingParitioner, it is really important to use
keys which can give you a lexically sortable range to scan when you need to
find them, so that you can use get_range_slice etc.
There are other approaches however - in some cases it may be possible to use
columns instead of rows there. But you'd still need keys for the columns.
A straightforward way of generating unique IDs for your objects is to add an
incrementing ID (managed locally) to the host name of the (client) node
where they were generated. But this is probably not helpful in most cases.
Mark
Re: How to generate 'unique' identifiers for use in Cassandra
Posted by Andriy Bohdan <a....@gmail.com>.
There's no easy and efficient way to implement auto_increment keys in
cassandra. So people usually use UUIDs
(http://en.wikipedia.org/wiki/UUID) for this purpose, which is
considered globally unique.
If you can use one of the fields from your data model as a unique key,
better use it instead of generating additional keys.
2010/4/26 Roland Hänel <ro...@haenel.me>:
> Typically, in the SQL world we use things like AUTO_INCREMENT columns that
> let us create a unique key automatically if a row is inserted into a table.
>
> What do you guys usually do to create identifiers for use in Cassandra?
>
> Do we only rely on "currentTimeMills() + random()" to create something that
> is 'unique enough' (but theoretically not fail-safe)? Or are some people
> here using systems like ZooKeeper for this purpose?
>
> -Roland
>
>
--
Andriy
Re: How to generate 'unique' identifiers for use in Cassandra
Posted by Miguel Verde <mi...@gmail.com>.
http://wiki.apache.org/cassandra/UUID if you don't need transactional
ordering, ZooKeeper or something comparable if you do.
2010/4/26 Roland Hänel <ro...@haenel.me>
> Typically, in the SQL world we use things like AUTO_INCREMENT columns that
> let us create a unique key automatically if a row is inserted into a table.
>
> What do you guys usually do to create identifiers for use in Cassandra?
>
> Do we only rely on "currentTimeMills() + random()" to create something that
> is 'unique enough' (but theoretically not fail-safe)? Or are some people
> here using systems like ZooKeeper for this purpose?
>
> -Roland
>
>