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

Ulf Wiger (TN/EAB) ulf.wiger@REDACTED
Tue Nov 6 17:56:35 CET 2007


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?

If you only care that the ID is unique, then
{node(), erlang:now()} is pretty simple and fast.

There are some extreme cases where it might not be
guaranteed to be unique (primarily if the system clock
is changed back a significant amount).

BR,
Ulf W



More information about the erlang-questions mailing list