[erlang-questions] Mnesia and autogenerated ids

Ulf Wiger ulf@REDACTED
Thu Aug 7 23:19:31 CEST 2008


2008/8/7 zambal <zambal@REDACTED>:
>
>
> If the only requirement of an ID is to be unique, why would you choose
> for another method than using now()?
>
> Or in other words, what are possible drawbacks of using now() as a
> unique ID generator?

Now is guaranteed to be unique on a given node, while that node is
running. Two different nodes can easily* generate the same now()
value. That's why {node(), now()} is used.

Of course, if the node is restarted and the system clock is altered,
you can still have duplication of IDs*. This problem can be addressed
by using NTP against a reliable time reference.

* Since now() has microsecond resolution, the probability is likely
small, unless IDs are created at a fearsome rate.

BR,
Ulf W



More information about the erlang-questions mailing list