incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Goodall <matt.good...@gmail.com>
Subject Re: Deleted docs can be accidentally resurrected
Date Wed, 18 Nov 2009 23:51:49 GMT
2009/11/18 Sebastian Cohnen <sebastiancohnen@googlemail.com>:
> afaik, this behavior is normal. you just created another (and new) resource/document.
>
> have a look (the database test is new and never contained docs with id 'foo' or 'foobar'):
>
> $ curl -X PUT -d '{"_id": "foo", "_rev": "1-967a00dff5e02add41819138abb3284d", "num":
1}' "http://localhost:5984/test/foo"
> {"ok":true,"id":"foo","rev":"2-65371ad05fc99a9b794f68c6003bc8da"}
>
> $ curl -X PUT -d '{"_id": "foobar", "_rev": "4-anythingyouwant", "num": 1}' "http://localhost:5984/test/foobar"
> {"ok":true,"id":"foobar","rev":"5-084106c9189a346875996e76c1833630"}

Hmm, seems wrong to me although I can imagine that's useful during
replication (which doesn't mean it should work for a PUT). However,
why does the following fail then:

$ curl -X "PUT" -d '{}' "http://localhost:15984/test/foo"
{"ok":true,"id":"foo","rev":"1-967a00dff5e02add41819138abb3284d"}
$ curl -X "PUT" -d '{"_id": "foo", "_rev":
"1-967a00dff5e02add41819138abb3284d"}'
"http://localhost:15984/test/foo"
{"ok":true,"id":"foo","rev":"2-7051cbe5c8faecd085a3fa619e6e6337"}
$ curl -X "DELETE"
"http://localhost:15984/test/foo?rev=2-7051cbe5c8faecd085a3fa619e6e6337"
{"ok":true,"id":"foo","rev":"3-7379b9e515b161226c6559d90c4dc49f"}
$ curl -X "PUT" -d '{"_id": "foo", "_rev":
"1-967a00dff5e02add41819138abb3284d"}'
"http://localhost:15984/test/foo"
{"error":"conflict","reason":"Document update conflict."}

- Matt

>
>
> cheers,
>
> tisba / Sebastian
>
> On 18.11.2009, at 23:56, Matt Goodall wrote:
>
>> Hi,
>>
>> I swear I've reported this odd behaviour before but I can't find any
>> mention of it now ...
>>
>> I have some code with a race condition that is caused by what I
>> believe is a bug in CouchDB - a deleted document can be updated using
>> an old, valid rev.
>>
>> If a document has not been deleted then CouchDB correctly returns a
>> conflict error if the latest rev is not sent. However, once deleted,
>> any rev in the docs history can be sent as the update and, as long as
>> the doc is changed in some way, the document will be resurrected with
>> a rev whose sequence is 1 more than that sent in the update.
>>
>> Create new doc ...
>> $ curl -X "PUT" -d '{"_id": "foo"}' http://localhost:15984/test/foo
>> {"ok":true,"id":"foo","rev":"1-967a00dff5e02add41819138abb3284d"}
>>
>> Update a couple of times to move the rev on ...
>> $ curl -X "PUT" -d '{"_id": "foo", "_rev":
>> "1-967a00dff5e02add41819138abb3284d"}' http://localhost:15984/test/foo
>> {"ok":true,"id":"foo","rev":"2-7051cbe5c8faecd085a3fa619e6e6337"}
>> $ curl -X "PUT" -d '{"_id": "foo", "_rev":
>> "2-7051cbe5c8faecd085a3fa619e6e6337"}' http://localhost:15984/test/foo
>> {"ok":true,"id":"foo","rev":"3-825cb35de44c433bfb2df415563a19de"}
>>
>> Delete the doc ...
>> $ curl -X "DELETE"
>> "http://localhost:15984/test/foo?rev=3-825cb35de44c433bfb2df415563a19de"{"ok":true,"id":"foo","rev":"4-1df13287548620bf858cf9d1b810972a"}
>>
>> Update using an old rev, changing something ...
>> $ curl -X "PUT" -d '{"_id": "foo", "_rev":
>> "1-967a00dff5e02add41819138abb3284d", "num": 1}'
>> http://localhost:15984/test/foo
>> {"ok":true,"id":"foo","rev":"2-65371ad05fc99a9b794f68c6003bc8da"}
>>
>> Now, I can sort of understand how something like that might happen
>> during replication but there's no replication going on here and
>> there's no conflict created in the database.
>>
>> I can't think of a way around the problem at the moment, other than
>> marking the document for deletion and then sweeping it later when
>> something else is hopefully not going to be touching the document.
>> But, frankly, that's horrible,
>>
>> - Matt
>
>

Mime
View raw message