mnesia primary key creation

Ulf Wiger (AL/EAB) ulf.wiger@REDACTED
Fri Jun 30 11:47:44 CEST 2006


I sketched the attached code for maintaining a node-specific sequence
number in a cluster of nodes. The code is untested - probably doesn't
even compile, and upon reflection, I'd do away with all the dirty ops.
Basically, you should never use dirty ops on replicated tables.

The thing I was after was a system-unique object identifier which was
compact enough to be human- and URL-friendly.

For cheap(in terms of CPU cost) automatic primary keys, I tend to use 

oid() -> {node(), erlang:now()}.

Given a reasonably well-behaved system clock(*), this is certain to give
unique values - increasing values, even - each time.

(*) AFAIK, even though it's not documented, erlang:now() is derived from
sys_gethrtime(), except on Win32, where it's derived from GetTickCount()
- I gave up before understanding from the source how erlang:now()
relates to "zero hour" on Windows. A cursory inspection of the code made
me doubt that my statement holds true for Windows. Correct me, please,
anyone. 

BR,
Ulf W

> -----Original Message-----
> From: owner-erlang-questions@REDACTED 
> [mailto:owner-erlang-questions@REDACTED] On Behalf Of Roberto Saccon
> Sent: den 30 juni 2006 03:59
> To: erlang-questions@REDACTED
> Subject: mnesia primary key creation
> 
> I am wondering whether experienced erlang developers have 
> something better in their best-practises-treasure-box than 
> what I have come up with to create mnesia primary keys:
> 
> 1. use "ordered_set" tables
> 
> 2. use "mnesia:dirty_last(myTable)" to get the last inserted 
> key and increment it for a new key before inserting a new record.
> 
> 
> regards
> --
> Roberto Saccon
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bbsOid.erl
Type: application/octet-stream
Size: 2231 bytes
Desc: bbsOid.erl
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20060630/edd5e16e/attachment.obj>


More information about the erlang-questions mailing list