couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Davis <paul.joseph.da...@gmail.com>
Subject Re: Write race conditions, working without _rev
Date Fri, 05 Nov 2010 16:03:43 GMT
On Fri, Nov 5, 2010 at 11:57 AM, Michael <newmaniese@gmail.com> wrote:
> Hello everyone;
>
> Thanks again for all the help that I have gotten with Couch, this
> group has really been helpful for my learning process.
>
> I have gotten so far in my application that I am starting to find some
> problems. The biggest one I have found is actually pertaining to
> adding a _rev to every save. I read the existing object and pull the
> _rev from that. This however creates a race condition where an
> object's _rev might be out of date while I save.
>
> In reality, I would love to write without a read--save a little
> overhead-- but everything I have read and tried says that this will
> produce an error. How do I get around this sort of race condition?
> Even better, is there a way to update an object with reading first.
>
> The second part is also a question in this article
> http://perfcap.blogspot.com/2010/10/comparing-nosql-availability-models.html
> from Adrian Cockcroft (part 2 of question 4).
>
> Thanks for the help again,
>
> Michael
>

I'm confused about your concern a bout a race condition when requiring
_rev to be specified. Not specifying a _rev doesn't prevent a race
condition, it just prevents you from knowing whether you just trampled
an update.

For instance, in the case where a _rev is required and two people
attempt to write simultaneously, one person will get a conflict error.
The person receiving the error will then know that they have to look
at the current value and figure out how to resolve the conflict.

In the second case, the second person to write the document wins,
erasing any changes the first write's effects. The first writer will
then be in a state where his view of the database will be
inconsistent. The thing his, he can't know because without requiring a
_rev token he'll never get a notification of any sort of error.

HTH,
Paul Davis

Mime
View raw message