Re: UUIDs generated using ossp-uuid on windows not unique

Lists: pgsql-bugs
From: Meetesh Karia <meetesh(dot)karia(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: UUIDs generated using ossp-uuid on windows not unique
Date: 2008-06-16 17:03:09
Message-ID: 48569CCD.3040600@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

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


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: meetesh(dot)karia(at)alumni(dot)duke(dot)edu
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: UUIDs generated using ossp-uuid on windows not unique
Date: 2008-06-16 18:25:17
Message-ID: 6099.1213640717@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Meetesh Karia <meetesh(dot)karia(at)gmail(dot)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&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


From: Stefan Kaltenbrunner <stefan(at)kaltenbrunner(dot)cc>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: meetesh(dot)karia(at)alumni(dot)duke(dot)edu, pgsql-bugs(at)postgresql(dot)org
Subject: Re: UUIDs generated using ossp-uuid on windows not unique
Date: 2008-06-16 20:01:57
Message-ID: 4856C6B5.2030303@kaltenbrunner.cc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Tom Lane wrote:
> Meetesh Karia <meetesh(dot)karia(at)gmail(dot)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&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


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stefan Kaltenbrunner <stefan(at)kaltenbrunner(dot)cc>
Cc: meetesh(dot)karia(at)alumni(dot)duke(dot)edu, pgsql-bugs(at)postgresql(dot)org
Subject: Re: UUIDs generated using ossp-uuid on windows not unique
Date: 2008-06-16 22:57:41
Message-ID: 8911.1213657061@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Stefan Kaltenbrunner <stefan(at)kaltenbrunner(dot)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


From: "Hiroshi Saito" <z-saito(at)guitar(dot)ocn(dot)ne(dot)jp>
To: "Stefan Kaltenbrunner" <stefan(at)kaltenbrunner(dot)cc>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Dave Page" <dpage(at)postgresql(dot)org>
Cc: <meetesh(dot)karia(at)alumni(dot)duke(dot)edu>, <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: UUIDs generated using ossp-uuid on windows not unique
Date: 2008-06-17 04:21:04
Message-ID: 017601c8d031$8ee2eaf0$0d01a8c0@IBMC9A0F63B40D
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

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(at)sss(dot)pgh(dot)pa(dot)us>

> Stefan Kaltenbrunner <stefan(at)kaltenbrunner(dot)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(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs


From: "Dave Page" <dpage(at)postgresql(dot)org>
To: "Hiroshi Saito" <z-saito(at)guitar(dot)ocn(dot)ne(dot)jp>
Cc: "Stefan Kaltenbrunner" <stefan(at)kaltenbrunner(dot)cc>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, meetesh(dot)karia(at)alumni(dot)duke(dot)edu, pgsql-bugs(at)postgresql(dot)org
Subject: Re: UUIDs generated using ossp-uuid on windows not unique
Date: 2008-06-17 07:35:27
Message-ID: 937d27e10806170035g62fc6472ieaf1b97d5af3caea@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

On Tue, Jun 17, 2008 at 5:21 AM, Hiroshi Saito <z-saito(at)guitar(dot)ocn(dot)ne(dot)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


From: "Hiroshi Saito" <z-saito(at)guitar(dot)ocn(dot)ne(dot)jp>
To: "Dave Page" <dpage(at)postgresql(dot)org>
Cc: "Stefan Kaltenbrunner" <stefan(at)kaltenbrunner(dot)cc>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, <meetesh(dot)karia(at)alumni(dot)duke(dot)edu>, <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: UUIDs generated using ossp-uuid on windows not unique
Date: 2008-06-17 09:25:17
Message-ID: 027101c8d05c$0eb487a0$0d01a8c0@IBMC9A0F63B40D
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

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(at)postgresql(dot)org>

> On Tue, Jun 17, 2008 at 5:21 AM, Hiroshi Saito <z-saito(at)guitar(dot)ocn(dot)ne(dot)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(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs


From: "Dave Page" <dpage(at)postgresql(dot)org>
To: "Hiroshi Saito" <z-saito(at)guitar(dot)ocn(dot)ne(dot)jp>
Cc: "Stefan Kaltenbrunner" <stefan(at)kaltenbrunner(dot)cc>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, meetesh(dot)karia(at)alumni(dot)duke(dot)edu, pgsql-bugs(at)postgresql(dot)org
Subject: Re: UUIDs generated using ossp-uuid on windows not unique
Date: 2008-06-17 09:41:08
Message-ID: 937d27e10806170241k518c45d3u84e8448650465fbb@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

On Tue, Jun 17, 2008 at 10:25 AM, Hiroshi Saito
<z-saito(at)guitar(dot)ocn(dot)ne(dot)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


From: "Hiroshi Saito" <z-saito(at)guitar(dot)ocn(dot)ne(dot)jp>
To: "Dave Page" <dpage(at)postgresql(dot)org>
Cc: "Stefan Kaltenbrunner" <stefan(at)kaltenbrunner(dot)cc>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, <meetesh(dot)karia(at)alumni(dot)duke(dot)edu>, <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: UUIDs generated using ossp-uuid on windows not unique
Date: 2008-06-17 10:17:46
Message-ID: 02ac01c8d063$6396b520$0d01a8c0@IBMC9A0F63B40D
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

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(at)postgresql(dot)org>

> On Tue, Jun 17, 2008 at 10:25 AM, Hiroshi Saito
> <z-saito(at)guitar(dot)ocn(dot)ne(dot)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


From: Meetesh Karia <meetesh(dot)karia(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Stefan Kaltenbrunner <stefan(at)kaltenbrunner(dot)cc>, meetesh(dot)karia(at)alumni(dot)duke(dot)edu, pgsql-bugs(at)postgresql(dot)org
Subject: Re: UUIDs generated using ossp-uuid on windows not unique
Date: 2008-06-17 10:58:19
Message-ID: 485798CB.2090505@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

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:
> Stefan Kaltenbrunner <stefan(at)kaltenbrunner(dot)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
>


From: "Dave Page" <dpage(at)postgresql(dot)org>
To: "Hiroshi Saito" <z-saito(at)guitar(dot)ocn(dot)ne(dot)jp>
Cc: "Stefan Kaltenbrunner" <stefan(at)kaltenbrunner(dot)cc>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, meetesh(dot)karia(at)alumni(dot)duke(dot)edu, pgsql-bugs(at)postgresql(dot)org
Subject: Re: UUIDs generated using ossp-uuid on windows not unique
Date: 2008-06-17 11:01:53
Message-ID: 937d27e10806170401i454f636doed3a4f0a7d2b43fc@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

On Tue, Jun 17, 2008 at 11:17 AM, Hiroshi Saito
<z-saito(at)guitar(dot)ocn(dot)ne(dot)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