mnesia primary key creation

Roberto Saccon <>
Tue Jul 4 21:31:26 CEST 2006


I liked the cheap solution:

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

but how can I turn erlang:now() into a String ?? (which probablly
won't look very URL-friendly)

I thouhgt of turing it into a list, then into a binary, then base64
encoding it, but
   list_to_binary(tuple_to_list(erlang:now()))
does not work.

regards
Roberto

On 6/30/06, Ulf Wiger (AL/EAB) <> wrote:
>
> 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: 
> > [mailto:] On Behalf Of Roberto Saccon
> > Sent: den 30 juni 2006 03:59
> > To: 
> > 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
> >
>
>
>


-- 
Roberto Saccon



More information about the erlang-questions mailing list