[erlang-questions] how: mnesia: id/generator in a cluster
Fri Nov 9 15:44:11 CET 2007
Can't GUID or make_ref/0 be used for this somehow?
make_ref() -> ref()
Returns an almost unique reference.
The returned reference will reoccur after approximately 2^82 calls;
therefore it is unique enough for practical purposes.
Dmitri Girenko wrote:
> Hi all,
> Having come from J2EE world I find it very difficult to get rid of all
> the patterns that I'm used to. There is one that can be named ID
> I have a set of unique objects that have to be stored in the DB
> (mnesia). I have to generate short unique numeric ID for those items. In
> my previous life usually a DB procedure/generators were used to ensure
> ID uniqueness in a cluster environment. But how can I achieve this
> functionality in OTP?
> Here are a few ideas that come to my mind:
> 1. use ordered_set and select last.id + 1.
> Adds 1 extra select per insert.
> 2. use table size + 1.
> 1 extra query, but maybe it's optimized enough?
> Both these have runtime overhead + race conditions.
> 3. create a separate singleton process that initializes counter to
> table_size + 1 and dispatches the "next values".
> OMG. Singleton in a cluster. Maybe application with failover is
> better? But why waste a whole application on just sequence generator.
> 4. Use phash(Item).
> but how to handle collisions then?
> Any recommendations?
> Best regards,
> Dmitri Girenko
> erlang-questions mailing list
View this message in context: http://www.nabble.com/how%3A-mnesia%3A-id-generator-in-a-cluster-tf4759227.html#a13668269
Sent from the Erlang Questions mailing list archive at Nabble.com.
More information about the erlang-questions