You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Chris Stockton <ch...@gmail.com> on 2010/03/25 00:18:27 UTC

Document availability in /_all_docs

Hello,

We have certain types of design documents within a database that
contain properties with values which must be unique. These design
documents are named in such a way I may do a _all_docs call to
retrieve them. I then check the _all_docs call (with include_docs =
true) to make sure when saving a new design document of this specific
type that the property does not exist.

I understand and accept that it is possible between the check, and the
actual PUT to the server, another document is saved, this is okay and
I am designing for this. The resolution model we would like to follow
is to rename the last saved document to preserve uniqueness. Our plan
is after each document save, then see if more then one exists, if so,
rename our document.

The only question this leaves, is after a document insert, is it then
immediately available to _all_docs? Illustrated example:

  in N parallel processes ->
    save doc ->
      { _id: '_design/foo_M<UNIQID>',
      uniqueProperty: 'duplicate' }

  check for uniqueness ->
    db/_all_docs?startkey="foo_M<UNIQID>"&endkey="foo\u9999" ->
       foreach _all_docs ->
         check if doc has uniq property ->
             if so, rename above docs uniqueProperty, otherwise do nothing

If my approach is incorrect or _all_docs could have a lapse and allow
this race condition I am very open to alternatives to guarantee
uniqueness. At times I believe a couchdb/db_1/_semaphore interface
might be of use to create user space atomic operations.

Thank you,

-Chris

Re: Document availability in /_all_docs

Posted by Adam Kocoloski <ko...@apache.org>.
On Mar 24, 2010, at 4:18 PM, Chris Stockton wrote:

> Hello,
> 
> We have certain types of design documents within a database that
> contain properties with values which must be unique. These design
> documents are named in such a way I may do a _all_docs call to
> retrieve them. I then check the _all_docs call (with include_docs =
> true) to make sure when saving a new design document of this specific
> type that the property does not exist.
> 
> I understand and accept that it is possible between the check, and the
> actual PUT to the server, another document is saved, this is okay and
> I am designing for this. The resolution model we would like to follow
> is to rename the last saved document to preserve uniqueness. Our plan
> is after each document save, then see if more then one exists, if so,
> rename our document.
> 
> The only question this leaves, is after a document insert, is it then
> immediately available to _all_docs?

Yes, you'll always see it in _all_docs.  Best,

Adam