Setup a loop

This assumes you've already set up ID with the date:time

I=0
LOOP
  I += 1
  WRITE.ID = ID : '*' : I
  READV JUST.CHECKING FROM FILE.NAME, WRITE.ID, 0 ELSE
    WRITE REC ON FILE.NAME, WRITE.ID
    EXIT
  END
REPEAT

This will always append *1 to the end of the ID unless it already exists.
If it does the loop will engage and will try *2, *3, ... until it hits an
unused ID.

I've used this several times in the past with total success.  However, the
above code is untested so there could be a typo, etc., but I hope you get
the idea!


hth, Allen



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Marco Manyevere
Sent: Thursday, April 24, 2008 02:55
To: [email protected]
Subject: [U2] Guaranteed unique sequential keys


What is the most reliable way to generate unique sequential keys without
having to resort to a record on disk updated through readu/write? The keys
don't have to be contiguous but only be sortable in the order in which they
were generated by several phantom processes running concurrently. I'm
currently approximating this using a concatenation of date and time with
millisecondsB but I'm worried about the possibility of two phantoms
generating
exactly the same key.
B
Although no collision has been detected so far, I
have added an extra check where after generating the key I first test if a
record with that key exists. If so IB increment and append aB serial number
and repeat the test until aB unique key is found. ItB seems to be working
well
but I still think there is a better way to do this.
B
Thanks for any help.
B
Marco.


      __________________________________________________________
Sent
from Yahoo! Mail.
A Smarter Email http://uk.docs.yahoo.com/nowyoucan.html
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to