couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Stockton <chrisstockto...@gmail.com>
Subject Document availability in <db>/_all_docs
Date Wed, 24 Mar 2010 23:18:27 GMT
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

Mime
View raw message