[erlang-questions] Use of uuidgen with a mnesia application

Darren New dnew@REDACTED
Fri Jun 6 19:31:26 CEST 2008


Paul Fisher wrote:
> On Fri, 2008-06-06 at 09:24 -0700, Darren New wrote:
>> Paul Fisher wrote:
>>> That is not guaranteed to be unique. 
>> I would hash the contents of the record itself. If you get a collision, 
>> it's probably because the records are identical anyway. :-)
> 
> That was my point, performing the SHA hash on
> term_to_binary( {make_ref(), now()} ) does not alter the uniqueness of
> the result.  It only randomizes the distribution of the generated "id
> values".

The important part of my statement was not "sha1" but "actual contents."

For example, in the system I have now, I generate fingerprints for music 
and put them in a database. Since there are a number of independent 
servers in separate cities for which I'm generating fingerprints, the 
identification could be one of two things: The host name + pid + 
timestamp (which can be messy), or just the sha1 of the actual contents 
of the audio file getting fingerprinted. If the sha1 comes out the same 
both times, the most likely causes is that I fingerprinted the same 
digital version of the same song twice.

Use the real life stuff-that-wont-change as the key for the record. (Or 
a hash thereof, if you want a single unique string.) As soon as you 
start making up arbitrary values and trying to map real-world items onto 
them, you start having to manage the arbitrary-value generation and the 
mapping.

Of course, it's difficult to run a human being through SHA1, so at some 
point you need to pick something you think won't change or otherwise 
handle the primary key changing (say, by chaining to the records from 
before the patient changed names or something).

-- 
   Darren New / San Diego, CA, USA (PST)
     "That's pretty. Where's that?"
          "It's the Age of Channelwood."
     "We should go there on vacation some time."



More information about the erlang-questions mailing list