UUIDs generated using ossp-uuid on windows not unique

Started by Meetesh Kariaalmost 18 years ago11 messagesbugs
Jump to latest
#1Meetesh Karia
meetesh.karia@gmail.com

Hi all,

This may not be the appropriate list to discuss this on (since it looks
like the bug is in the underlying library), but as the win32 port was
done because of postgresql (as far as I can tell), I wanted to see if
anyone had run into this and/or had any workarounds:

As best as I can tell, the problem is caused because generation of v1
UUIDs uses GetSystemTimeAsFileTime which is stated to have a resolution
of 100 nanoseconds but in practice has a resolution of around 15ms
(http://www.ddj.com/showArticle.jhtml?documentID=win0305a&pgno=17).

Here's a snippet from log of id creation from a java app using Hibernate
on 32-bit Windows Vista Home Premium:

17:59:50,007 DEBUG [main][org.hibernate.id.GUIDGenerator] GUID
identifier generated: 400770c0-3bbd-11dd-9dcb-bfe9e8f8c4e3
17:59:50,016 DEBUG [main][org.hibernate.id.GUIDGenerator] GUID
identifier generated: 4008d050-3bbd-11dd-bcfd-efd9d1bca81a
17:59:50,017 DEBUG [main][org.hibernate.id.GUIDGenerator] GUID
identifier generated: 4008f760-3bbd-11dd-86d8-3b7fffcb1fd0
17:59:50,018 DEBUG [main][org.hibernate.id.GUIDGenerator] GUID
identifier generated: 40091e70-3bbd-11dd-a129-c3ff008d4230

17:59:50,019 DEBUG [main][org.hibernate.id.GUIDGenerator] GUID
identifier generated: 40094580-3bbd-11dd-91d4-3f3c34e3d932
17:59:50,020 DEBUG [main][org.hibernate.id.GUIDGenerator] GUID
identifier generated: 40094580-3bbd-11dd-91d4-3f3c34e3d932

17:59:50,101 DEBUG [main][org.hibernate.id.GUIDGenerator] GUID
identifier generated: 4015a190-3bbd-11dd-9639-9b73321c2f74
17:59:50,109 DEBUG [main][org.hibernate.id.GUIDGenerator] GUID
identifier generated: 4016da10-3bbd-11dd-91d7-df8cd7608cfc
17:59:50,118 DEBUG [main][org.hibernate.id.GUIDGenerator] GUID
identifier generated: 401860b0-3bbd-11dd-8ff9-5f0d982e530e
17:59:50,129 DEBUG [main][org.hibernate.id.GUIDGenerator] GUID
identifier generated: 4019e750-3bbd-11dd-8e23-2315e240bab8
17:59:50,130 DEBUG [main][org.hibernate.id.GUIDGenerator] GUID
identifier generated: 401a3570-3bbd-11dd-9af2-8350eef5ace8
17:59:50,131 DEBUG [main][org.hibernate.id.GUIDGenerator] GUID
identifier generated: 401a5c80-3bbd-11dd-b91d-1fb0760aeab8
17:59:50,132 DEBUG [main][org.hibernate.id.GUIDGenerator] GUID
identifier generated: 401a5c80-3bbd-11dd-b91d-1fb0760aeab8

Thoughts? Has anyone run into this before? Worked around it?

Thanks,
Meetesh

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Meetesh Karia (#1)
Re: UUIDs generated using ossp-uuid on windows not unique

Meetesh Karia <meetesh.karia@gmail.com> writes:

As best as I can tell, the problem is caused because generation of v1
UUIDs uses GetSystemTimeAsFileTime which is stated to have a resolution
of 100 nanoseconds but in practice has a resolution of around 15ms
(http://www.ddj.com/showArticle.jhtml?documentID=win0305a&amp;pgno=17).

Well, any real-time clock reading is going to have finite resolution.
If your app is expecting that version-1 UUIDs generated in rapid
succession will be distinct, I think your app is broken. It's just
a little more obvious on Windows :-(.

Perhaps the v4 generation method would work better for you?

regards, tom lane

#3Stefan Kaltenbrunner
stefan@kaltenbrunner.cc
In reply to: Tom Lane (#2)
Re: UUIDs generated using ossp-uuid on windows not unique

Tom Lane wrote:

Meetesh Karia <meetesh.karia@gmail.com> writes:

As best as I can tell, the problem is caused because generation of v1
UUIDs uses GetSystemTimeAsFileTime which is stated to have a resolution
of 100 nanoseconds but in practice has a resolution of around 15ms
(http://www.ddj.com/showArticle.jhtml?documentID=win0305a&amp;pgno=17).

Well, any real-time clock reading is going to have finite resolution.
If your app is expecting that version-1 UUIDs generated in rapid
succession will be distinct, I think your app is broken. It's just
a little more obvious on Windows :-(.

Perhaps the v4 generation method would work better for you?

actually this has been reported before and seems to be an issue in the
windows port of the ossp-uuid library:

http://archives.postgresql.org/pgsql-bugs/2008-05/msg00059.php

Stefan

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Stefan Kaltenbrunner (#3)
Re: UUIDs generated using ossp-uuid on windows not unique

Stefan Kaltenbrunner <stefan@kaltenbrunner.cc> writes:

Tom Lane wrote:

Perhaps the v4 generation method would work better for you?

actually this has been reported before and seems to be an issue in the
windows port of the ossp-uuid library:
http://archives.postgresql.org/pgsql-bugs/2008-05/msg00059.php

Oh, so that doesn't work either :-(. However, at least it's been
fixed upstream:
http://archives.postgresql.org/pgsql-bugs/2008-05/msg00070.php
http://cvs.ossp.org/pkg/lib/uuid/ChangeLog

regards, tom lane

#5Hiroshi Saito
z-saito@guitar.ocn.ne.jp
In reply to: Meetesh Karia (#1)
Re: UUIDs generated using ossp-uuid on windows not unique

Hi.

Sorry, late the information.....
My patch was applied after the review of Ralf-san. However, The timing of a
release was different. Then, patch is only current CVS-HEAD.
http://cvs.ossp.org/chngview?cn=6001

I thought that this problem was very important. It was sufficient reason to
apply to 8.3.3 of pginstaller. Therefore, It should return the result of a wish.

Regards,
Hiroshi Saito

----- Original Message -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>

Show quoted text

Stefan Kaltenbrunner <stefan@kaltenbrunner.cc> writes:

Tom Lane wrote:

Perhaps the v4 generation method would work better for you?

actually this has been reported before and seems to be an issue in the
windows port of the ossp-uuid library:
http://archives.postgresql.org/pgsql-bugs/2008-05/msg00059.php

Oh, so that doesn't work either :-(. However, at least it's been
fixed upstream:
http://archives.postgresql.org/pgsql-bugs/2008-05/msg00070.php
http://cvs.ossp.org/pkg/lib/uuid/ChangeLog

regards, tom lane

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#6Dave Page
dpage@pgadmin.org
In reply to: Hiroshi Saito (#5)
Re: UUIDs generated using ossp-uuid on windows not unique

On Tue, Jun 17, 2008 at 5:21 AM, Hiroshi Saito <z-saito@guitar.ocn.ne.jp> wrote:

Hi.

Sorry, late the information.....
My patch was applied after the review of Ralf-san. However, The timing of a
release was different. Then, patch is only current CVS-HEAD.
http://cvs.ossp.org/chngview?cn=6001

I thought that this problem was very important. It was sufficient reason to
apply to 8.3.3 of pginstaller. Therefore, It should return the result of a
wish.

It's not in 8.3.3 - I'm still waiting for details of how to build it,
as it's not exactly obvious.

--
Dave Page
EnterpriseDB UK: http://www.enterprisedb.com

#7Hiroshi Saito
z-saito@guitar.ocn.ne.jp
In reply to: Meetesh Karia (#1)
Re: UUIDs generated using ossp-uuid on windows not unique

Hi.

Um, I will arrange information and write wiki. .
Is it a suitable place?

This is some information.
http://winpg.jp/~saito/pg_work/OSSP_win32/
uuid-ossp.dll(MinGW compile) is this.
http://winpg.jp/~saito/pg_work/OSSP_win32/pg8.3.3-win-bin-uuid-ossp.zip

Regards,
Hiroshi Saito

----- Original Message -----
From: "Dave Page" <dpage@postgresql.org>

Show quoted text

On Tue, Jun 17, 2008 at 5:21 AM, Hiroshi Saito <z-saito@guitar.ocn.ne.jp> wrote:

Hi.

Sorry, late the information.....
My patch was applied after the review of Ralf-san. However, The timing of a
release was different. Then, patch is only current CVS-HEAD.
http://cvs.ossp.org/chngview?cn=6001

I thought that this problem was very important. It was sufficient reason to
apply to 8.3.3 of pginstaller. Therefore, It should return the result of a
wish.

It's not in 8.3.3 - I'm still waiting for details of how to build it,
as it's not exactly obvious.

--
Dave Page
EnterpriseDB UK: http://www.enterprisedb.com

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#8Dave Page
dpage@pgadmin.org
In reply to: Hiroshi Saito (#7)
Re: UUIDs generated using ossp-uuid on windows not unique

On Tue, Jun 17, 2008 at 10:25 AM, Hiroshi Saito
<z-saito@guitar.ocn.ne.jp> wrote:

Hi.

Um, I will arrange information and write wiki. . Is it a suitable place?

A README file at http://winpg.jp/~saito/pg_work/OSSP_win32/ would be enough.

This is some information. http://winpg.jp/~saito/pg_work/OSSP_win32/
uuid-ossp.dll(MinGW compile) is this.
http://winpg.jp/~saito/pg_work/OSSP_win32/pg8.3.3-win-bin-uuid-ossp.zip

We need a VC++ .lib for the installer. When I tried last time, I
unpacked the source, replaced the headers with those in the msvc
directory, and applied your patch. The build then failed with various
missing (unix-specific) headers iirc. Do you have a set of dummy
replacements someplace in your build environment?

--
Dave Page
EnterpriseDB UK: http://www.enterprisedb.com

#9Hiroshi Saito
z-saito@guitar.ocn.ne.jp
In reply to: Meetesh Karia (#1)
Re: UUIDs generated using ossp-uuid on windows not unique

Hi.

Please this.
http://winpg.jp/~saito/pg_work/OSSP_win32/msvc/

P.S)
sorry,
It did not have a machine, when it mailed with you before.

Regards,
Hiroshi Saito

----- Original Message -----
From: "Dave Page" <dpage@postgresql.org>

Show quoted text

On Tue, Jun 17, 2008 at 10:25 AM, Hiroshi Saito
<z-saito@guitar.ocn.ne.jp> wrote:

Hi.

Um, I will arrange information and write wiki. . Is it a suitable place?

A README file at http://winpg.jp/~saito/pg_work/OSSP_win32/ would be enough.

This is some information. http://winpg.jp/~saito/pg_work/OSSP_win32/
uuid-ossp.dll(MinGW compile) is this.
http://winpg.jp/~saito/pg_work/OSSP_win32/pg8.3.3-win-bin-uuid-ossp.zip

We need a VC++ .lib for the installer. When I tried last time, I
unpacked the source, replaced the headers with those in the msvc
directory, and applied your patch. The build then failed with various
missing (unix-specific) headers iirc. Do you have a set of dummy
replacements someplace in your build environment?

--
Dave Page
EnterpriseDB UK: http://www.enterprisedb.com

#10Meetesh Karia
meetesh.karia@gmail.com
In reply to: Tom Lane (#4)
Re: UUIDs generated using ossp-uuid on windows not unique

Using the dll from the link that Hiroshi posted actually fixed v1 in my
case (though perhaps it's just an unrelated side-effect caused by using
a different random number generator which might be slower???). Thanks!

Anyhow, I would have expected v1 to work fine in this case too as the
ossp-uuid implementation has provisions for preventing overlapping ids
when they're generated in rapid succession. And, as I was only
generating about 1 uuid/ms, I didn't think that would be pushing the
limits of the algorithm.

Thanks again everyone,
Meetesh

Tom Lane wrote:

Show quoted text

Stefan Kaltenbrunner <stefan@kaltenbrunner.cc> writes:

Tom Lane wrote:

Perhaps the v4 generation method would work better for you?

actually this has been reported before and seems to be an issue in the
windows port of the ossp-uuid library:
http://archives.postgresql.org/pgsql-bugs/2008-05/msg00059.php

Oh, so that doesn't work either :-(. However, at least it's been
fixed upstream:
http://archives.postgresql.org/pgsql-bugs/2008-05/msg00070.php
http://cvs.ossp.org/pkg/lib/uuid/ChangeLog

regards, tom lane

#11Dave Page
dpage@pgadmin.org
In reply to: Hiroshi Saito (#9)
Re: UUIDs generated using ossp-uuid on windows not unique

On Tue, Jun 17, 2008 at 11:17 AM, Hiroshi Saito
<z-saito@guitar.ocn.ne.jp> wrote:

Hi.

Please this.
http://winpg.jp/~saito/pg_work/OSSP_win32/msvc/

Ahh, a makefile - that makes things somewhat clearer :-)

Thanks - I've updated the build machine so future releases will
include this fix.

--
Dave Page
EnterpriseDB UK: http://www.enterprisedb.com