couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Burton <>
Subject Re: Exist test?
Date Mon, 05 Nov 2012 19:40:48 GMT
I am mainly using it the context of initially populating a database. So there isn't any danger
of a race because there is only one user.

On Nov 5, 2012, at 12:47 PM, Jens Alfke <> wrote:

> On Nov 5, 2012, at 10:22 AM, Kevin Burton <> wrote:
>> I am calling CreateDocument<Document>() but I suspect that testing if the document
exists first may perform better in the long run. I am using DreamSeat for my driver but I
suspect other drivers have a similar "test". My problem is that I don't know what to test
for and I am unfamiliar with the available methods. Any one successfully use such a pattern
(preferably with DreamSeat) that tests for existence then creates if the document doesn't
exist? Keep in mind I don't initially have an id. Thank you.
> I don’t know anything about that particular API, but in general, check-then-create
doesn’t work well in a concurrent environment. It’s prone to race conditions where something
else creates the resource in between your check call and your create call. (The canonical
example is checking whether a file exists, then creating the file, which is a classic old
security hole in privileged Unix tools.)
> —Jens

View raw message