[erlang-questions] how: mnesia: id/generator in a cluster

Dmitri Girenko Dmitri.Girenko@REDACTED
Wed Nov 7 09:02:29 CET 2007


Thanks Ladislav, dirty_update_counter is exactly what I've been looking
for.

{node(), now()} is also a good idea, but I need a short and numeric ID
to embed into URL.

> -----Original Message-----
> From: erlang-questions-bounces@REDACTED [mailto:erlang-questions-
> bounces@REDACTED] On Behalf Of Ladislav Lenart
> Sent: 6. marraskuuta 2007 18:56
> Cc: erlang-questions@REDACTED
> Subject: Re: [erlang-questions] how: mnesia: id/generator in a cluster
> 
> 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
> > generator.
> >
> > 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?
> 
> Hello,
> 
> See mnesia:dirty_update_counter/3 and mnesia:dirty_read/2.
> They might be exactly what you are looking for.
> 
> Hope this helps,
> 
> Ladislav Lenart
> 
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list