You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Andrey Kuprianov <an...@gmail.com> on 2012/11/08 11:31:47 UTC

Re: are auto-generated uuids unique across server-instance

It's a uuid. It's unique wherever


On Thu, Nov 8, 2012 at 6:32 PM, svilen <az...@svilendobrev.com> wrote:

> hi
> are auto-generated uuids (when doc is saved without assigned id)
> unique across server-instance, or only within the database?
>
> i.e. can i take a doc from one database and write
> it as-is-without-the-_rev into another database?
> can that become a problem?
>
> ciao
> svil
>
> www.notionery.com
> www.svilendobrev.com
>

Re: are auto-generated uuids unique across server-instance

Posted by Nick North <no...@gmail.com>.
Not sure if this addresses your problem but...

The utc_id_suffix algorithm is intended for occasions when you want ids to
be time-ordered on each server, and you want to be able to distinguish
which server they originate from when replicating. The uuids are of the
form [timestamp]+[suffix] where the suffix is set in the server's ini file.
The Erlang clock guarantees to return a different and increasing value on
every call, so uuids are unique on each server, even if several arrive
during the same clock tick. By giving each server a different suffix you
can distinguish document origin, and you can deconstruct the uuid into the
timestamp and its suffix and use both in your view key if you want to deal
with the case where servers have different local times (you then have to
query the view for each server independently of course). You do need to
watch out for replication though, as this happens in parallel so documents
may replicate out of order, which makes it a little difficult to write a
client that picks up every document as it arrives.

utc_id_suffix is not in CouchDb 1.2 though - it's coming in 1.3.

Nick North


On 9 November 2012 01:31, Andrey Kuprianov <an...@gmail.com>wrote:

> Add a postfix to uuid. Just as an idea: uuid+[timetamp in ms]+[server
> identifier]
>
> So you will get something
> like cc606fe70aa52bd60da6c94835cda3ef-1349789839150-A for a document id.
>
> Then if you output all ids into a view with:
>
> function(doc) {
>      emit(doc._id, null);
> }
>
> you will get your docs chronologically ordered as you will also know which
> server they came from.
>
>
> On Fri, Nov 9, 2012 at 3:12 AM, svilen <az...@svilendobrev.com> wrote:
>
> > i'm asking this because i do have a machine that is 4minutes ahead
> > of others.. and thus a few things relying on (sorted-by) local
> > clock() timestamp went plop. And everyone-with-own-idea-of-time is
> > going to be the norm..
> >
> > so now i'm looking for some kind of autoincrementing suffix, additional
> > to server-side clock being stamped on documents.. coz incoming order
> > does matter (multiple in same microsecond). Looked at _local_seq for
> > that (by copy into another field to unlocal it), but not sure if it
> > is always increasing (or sufficienty "always"). probably is.
> >
> > anyway, thanks
> > svil
> >
> > On Thu, 8 Nov 2012 10:36:13 -0800
> > Mark Hahn <ma...@hahnca.com> wrote:
> >
> > > I use utc_random.  It is really useful.  Easy to sort by creation
> > > date. And you can even extract the creation date from the _id and
> > > save a field.
> > >
> > > On Thu, Nov 8, 2012 at 10:21 AM, Robert Newson <rn...@apache.org>
> > > wrote:
> > >
> > > > Hi,
> > > >
> > > > Here's the pertinent information on the various UUID algorithms
> > > > CouchDB supports;
> > > >
> > > > [uuids]
> > > > ; Known algorithms:
> > > > ;   random - 128 bits of random awesome
> > > > ;     All awesome, all the time.
> > > > ;   sequential - monotonically increasing ids with random increments
> > > > ;     First 26 hex characters are random. Last 6 increment in
> > > > ;     random amounts until an overflow occurs. On overflow, the
> > > > ;     random prefix is regenerated and the process starts over.
> > > > ;   utc_random - Time since Jan 1, 1970 UTC with microseconds
> > > > ;     First 14 characters are the time in hex. Last 18 are random.
> > > > ;   utc_id - Time since Jan 1, 1970 UTC with microseconds, plus
> > > > utc_id_suffix string
> > > > ;     First 14 characters are the time in hex. uuids/utc_id_suffix
> > > > string value is appended to these.
> > > >
> > > > The default is "sequential".
> > > >
> > > > B.
> > > >
> > > >
> > > > On 8 November 2012 18:13, Mark Hahn <ma...@hahnca.com> wrote:
> > > >
> > > > > http://en.wikipedia.org/wiki/Universally_unique_identifier
> > > > >
> > > > > On Thu, Nov 8, 2012 at 2:31 AM, Andrey Kuprianov <
> > > > > andrey.kouprianov@gmail.com> wrote:
> > > > >
> > > > > > It's a uuid. It's unique wherever
> > > > > >
> > > > > >
> > > > > > On Thu, Nov 8, 2012 at 6:32 PM, svilen <az...@svilendobrev.com>
> > > > > > wrote:
> > > > > >
> > > > > > > hi
> > > > > > > are auto-generated uuids (when doc is saved without assigned
> > > > > > > id) unique across server-instance, or only within the
> > > > > > > database?
> > > > > > >
> > > > > > > i.e. can i take a doc from one database and write
> > > > > > > it as-is-without-the-_rev into another database?
> > > > > > > can that become a problem?
> > > > > > >
> > > > > > > ciao
> > > > > > > svil
> > > > > > >
> > > > > > > www.notionery.com
> > > > > > > www.svilendobrev.com
> > > > > > >
> > > > > >
> > > > >
> > > >
> >
>

Re: are auto-generated uuids unique across server-instance

Posted by Andrey Kuprianov <an...@gmail.com>.
Add a postfix to uuid. Just as an idea: uuid+[timetamp in ms]+[server
identifier]

So you will get something
like cc606fe70aa52bd60da6c94835cda3ef-1349789839150-A for a document id.

Then if you output all ids into a view with:

function(doc) {
     emit(doc._id, null);
}

you will get your docs chronologically ordered as you will also know which
server they came from.


On Fri, Nov 9, 2012 at 3:12 AM, svilen <az...@svilendobrev.com> wrote:

> i'm asking this because i do have a machine that is 4minutes ahead
> of others.. and thus a few things relying on (sorted-by) local
> clock() timestamp went plop. And everyone-with-own-idea-of-time is
> going to be the norm..
>
> so now i'm looking for some kind of autoincrementing suffix, additional
> to server-side clock being stamped on documents.. coz incoming order
> does matter (multiple in same microsecond). Looked at _local_seq for
> that (by copy into another field to unlocal it), but not sure if it
> is always increasing (or sufficienty "always"). probably is.
>
> anyway, thanks
> svil
>
> On Thu, 8 Nov 2012 10:36:13 -0800
> Mark Hahn <ma...@hahnca.com> wrote:
>
> > I use utc_random.  It is really useful.  Easy to sort by creation
> > date. And you can even extract the creation date from the _id and
> > save a field.
> >
> > On Thu, Nov 8, 2012 at 10:21 AM, Robert Newson <rn...@apache.org>
> > wrote:
> >
> > > Hi,
> > >
> > > Here's the pertinent information on the various UUID algorithms
> > > CouchDB supports;
> > >
> > > [uuids]
> > > ; Known algorithms:
> > > ;   random - 128 bits of random awesome
> > > ;     All awesome, all the time.
> > > ;   sequential - monotonically increasing ids with random increments
> > > ;     First 26 hex characters are random. Last 6 increment in
> > > ;     random amounts until an overflow occurs. On overflow, the
> > > ;     random prefix is regenerated and the process starts over.
> > > ;   utc_random - Time since Jan 1, 1970 UTC with microseconds
> > > ;     First 14 characters are the time in hex. Last 18 are random.
> > > ;   utc_id - Time since Jan 1, 1970 UTC with microseconds, plus
> > > utc_id_suffix string
> > > ;     First 14 characters are the time in hex. uuids/utc_id_suffix
> > > string value is appended to these.
> > >
> > > The default is "sequential".
> > >
> > > B.
> > >
> > >
> > > On 8 November 2012 18:13, Mark Hahn <ma...@hahnca.com> wrote:
> > >
> > > > http://en.wikipedia.org/wiki/Universally_unique_identifier
> > > >
> > > > On Thu, Nov 8, 2012 at 2:31 AM, Andrey Kuprianov <
> > > > andrey.kouprianov@gmail.com> wrote:
> > > >
> > > > > It's a uuid. It's unique wherever
> > > > >
> > > > >
> > > > > On Thu, Nov 8, 2012 at 6:32 PM, svilen <az...@svilendobrev.com>
> > > > > wrote:
> > > > >
> > > > > > hi
> > > > > > are auto-generated uuids (when doc is saved without assigned
> > > > > > id) unique across server-instance, or only within the
> > > > > > database?
> > > > > >
> > > > > > i.e. can i take a doc from one database and write
> > > > > > it as-is-without-the-_rev into another database?
> > > > > > can that become a problem?
> > > > > >
> > > > > > ciao
> > > > > > svil
> > > > > >
> > > > > > www.notionery.com
> > > > > > www.svilendobrev.com
> > > > > >
> > > > >
> > > >
> > >
>

Re: are auto-generated uuids unique across server-instance

Posted by svilen <az...@svilendobrev.com>.
i'm asking this because i do have a machine that is 4minutes ahead
of others.. and thus a few things relying on (sorted-by) local
clock() timestamp went plop. And everyone-with-own-idea-of-time is
going to be the norm..

so now i'm looking for some kind of autoincrementing suffix, additional
to server-side clock being stamped on documents.. coz incoming order
does matter (multiple in same microsecond). Looked at _local_seq for
that (by copy into another field to unlocal it), but not sure if it
is always increasing (or sufficienty "always"). probably is.

anyway, thanks
svil

On Thu, 8 Nov 2012 10:36:13 -0800
Mark Hahn <ma...@hahnca.com> wrote:

> I use utc_random.  It is really useful.  Easy to sort by creation
> date. And you can even extract the creation date from the _id and
> save a field.
> 
> On Thu, Nov 8, 2012 at 10:21 AM, Robert Newson <rn...@apache.org>
> wrote:
> 
> > Hi,
> >
> > Here's the pertinent information on the various UUID algorithms
> > CouchDB supports;
> >
> > [uuids]
> > ; Known algorithms:
> > ;   random - 128 bits of random awesome
> > ;     All awesome, all the time.
> > ;   sequential - monotonically increasing ids with random increments
> > ;     First 26 hex characters are random. Last 6 increment in
> > ;     random amounts until an overflow occurs. On overflow, the
> > ;     random prefix is regenerated and the process starts over.
> > ;   utc_random - Time since Jan 1, 1970 UTC with microseconds
> > ;     First 14 characters are the time in hex. Last 18 are random.
> > ;   utc_id - Time since Jan 1, 1970 UTC with microseconds, plus
> > utc_id_suffix string
> > ;     First 14 characters are the time in hex. uuids/utc_id_suffix
> > string value is appended to these.
> >
> > The default is "sequential".
> >
> > B.
> >
> >
> > On 8 November 2012 18:13, Mark Hahn <ma...@hahnca.com> wrote:
> >
> > > http://en.wikipedia.org/wiki/Universally_unique_identifier
> > >
> > > On Thu, Nov 8, 2012 at 2:31 AM, Andrey Kuprianov <
> > > andrey.kouprianov@gmail.com> wrote:
> > >
> > > > It's a uuid. It's unique wherever
> > > >
> > > >
> > > > On Thu, Nov 8, 2012 at 6:32 PM, svilen <az...@svilendobrev.com>
> > > > wrote:
> > > >
> > > > > hi
> > > > > are auto-generated uuids (when doc is saved without assigned
> > > > > id) unique across server-instance, or only within the
> > > > > database?
> > > > >
> > > > > i.e. can i take a doc from one database and write
> > > > > it as-is-without-the-_rev into another database?
> > > > > can that become a problem?
> > > > >
> > > > > ciao
> > > > > svil
> > > > >
> > > > > www.notionery.com
> > > > > www.svilendobrev.com
> > > > >
> > > >
> > >
> >

Re: are auto-generated uuids unique across server-instance

Posted by Mark Hahn <ma...@hahnca.com>.
I use utc_random.  It is really useful.  Easy to sort by creation date.
 And you can even extract the creation date from the _id and save a field.

On Thu, Nov 8, 2012 at 10:21 AM, Robert Newson <rn...@apache.org> wrote:

> Hi,
>
> Here's the pertinent information on the various UUID algorithms CouchDB
> supports;
>
> [uuids]
> ; Known algorithms:
> ;   random - 128 bits of random awesome
> ;     All awesome, all the time.
> ;   sequential - monotonically increasing ids with random increments
> ;     First 26 hex characters are random. Last 6 increment in
> ;     random amounts until an overflow occurs. On overflow, the
> ;     random prefix is regenerated and the process starts over.
> ;   utc_random - Time since Jan 1, 1970 UTC with microseconds
> ;     First 14 characters are the time in hex. Last 18 are random.
> ;   utc_id - Time since Jan 1, 1970 UTC with microseconds, plus
> utc_id_suffix string
> ;     First 14 characters are the time in hex. uuids/utc_id_suffix string
> value is appended to these.
>
> The default is "sequential".
>
> B.
>
>
> On 8 November 2012 18:13, Mark Hahn <ma...@hahnca.com> wrote:
>
> > http://en.wikipedia.org/wiki/Universally_unique_identifier
> >
> > On Thu, Nov 8, 2012 at 2:31 AM, Andrey Kuprianov <
> > andrey.kouprianov@gmail.com> wrote:
> >
> > > It's a uuid. It's unique wherever
> > >
> > >
> > > On Thu, Nov 8, 2012 at 6:32 PM, svilen <az...@svilendobrev.com> wrote:
> > >
> > > > hi
> > > > are auto-generated uuids (when doc is saved without assigned id)
> > > > unique across server-instance, or only within the database?
> > > >
> > > > i.e. can i take a doc from one database and write
> > > > it as-is-without-the-_rev into another database?
> > > > can that become a problem?
> > > >
> > > > ciao
> > > > svil
> > > >
> > > > www.notionery.com
> > > > www.svilendobrev.com
> > > >
> > >
> >
>

Re: are auto-generated uuids unique across server-instance

Posted by Robert Newson <rn...@apache.org>.
Hi,

Here's the pertinent information on the various UUID algorithms CouchDB
supports;

[uuids]
; Known algorithms:
;   random - 128 bits of random awesome
;     All awesome, all the time.
;   sequential - monotonically increasing ids with random increments
;     First 26 hex characters are random. Last 6 increment in
;     random amounts until an overflow occurs. On overflow, the
;     random prefix is regenerated and the process starts over.
;   utc_random - Time since Jan 1, 1970 UTC with microseconds
;     First 14 characters are the time in hex. Last 18 are random.
;   utc_id - Time since Jan 1, 1970 UTC with microseconds, plus
utc_id_suffix string
;     First 14 characters are the time in hex. uuids/utc_id_suffix string
value is appended to these.

The default is "sequential".

B.


On 8 November 2012 18:13, Mark Hahn <ma...@hahnca.com> wrote:

> http://en.wikipedia.org/wiki/Universally_unique_identifier
>
> On Thu, Nov 8, 2012 at 2:31 AM, Andrey Kuprianov <
> andrey.kouprianov@gmail.com> wrote:
>
> > It's a uuid. It's unique wherever
> >
> >
> > On Thu, Nov 8, 2012 at 6:32 PM, svilen <az...@svilendobrev.com> wrote:
> >
> > > hi
> > > are auto-generated uuids (when doc is saved without assigned id)
> > > unique across server-instance, or only within the database?
> > >
> > > i.e. can i take a doc from one database and write
> > > it as-is-without-the-_rev into another database?
> > > can that become a problem?
> > >
> > > ciao
> > > svil
> > >
> > > www.notionery.com
> > > www.svilendobrev.com
> > >
> >
>

Re: are auto-generated uuids unique across server-instance

Posted by Mark Hahn <ma...@hahnca.com>.
http://en.wikipedia.org/wiki/Universally_unique_identifier

On Thu, Nov 8, 2012 at 2:31 AM, Andrey Kuprianov <
andrey.kouprianov@gmail.com> wrote:

> It's a uuid. It's unique wherever
>
>
> On Thu, Nov 8, 2012 at 6:32 PM, svilen <az...@svilendobrev.com> wrote:
>
> > hi
> > are auto-generated uuids (when doc is saved without assigned id)
> > unique across server-instance, or only within the database?
> >
> > i.e. can i take a doc from one database and write
> > it as-is-without-the-_rev into another database?
> > can that become a problem?
> >
> > ciao
> > svil
> >
> > www.notionery.com
> > www.svilendobrev.com
> >
>