incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Newson <rnew...@apache.org>
Subject Re: Inserted document "disappears" in the database
Date Thu, 28 Feb 2013 09:23:18 GMT
https://issues.apache.org/jira/browse/COUCHDB-1415

On 28 February 2013 08:38, Mikael H├Ągerbro
<mikael.hagerbro@foretagsplatsen.se> wrote:
> Hello,
>
> I think I found a bug in CouchDB 1.2.1 that makes it possible to insert a
> document that will be accepted but disappears in the database.
> The problem occurs after you run compact on a database with a document
> containing an attachment, then delete the document and try to insert a new
> document with the same id.
>
> How to reproduce the problem:
>
> # I have a newly created database named "test"
>
> mikael@couchdb:~$ curl http://127.0.0.1:5998/_all_dbs
> ["_users","test"]
>
> # Insert a document
>
> mikael@couchdb:~$ curl -H "Content-Type: application/json" -d '{"_id":"1"}'
> -X PUT http://127.0.0.1:5998/test/1
> {"ok":true,"id":"1","rev":"1-967a00dff5e02add41819138abb3284d"}
>
> # Add an attachment
>
> mikael@couchdb:~$ curl -H "Content-Type: application/json" -d 'data' -X PUT
> http://127.0.0.1:5998/test/1/test?rev=1-967a00dff5e02add41819138abb3284d
> {"ok":true,"id":"1","rev":"2-a8027b975388125d7d3d174a5e5c01d5"}
>
> # Run compact on the database
>
> mikael@couchdb:~$ curl -H "Content-Type: application/json" -X POST
> http://127.0.0.1:5998/test/_compact
> {"ok":true}
>
> # Delete the document
>
> mikael@couchdb:~$ curl -H "Content-Type: application/json" -X DELETE
> http://127.0.0.1:5998/test/1?rev=2-a8027b975388125d7d3d174a5e5c01d5
> {"ok":true,"id":"1","rev":"3-b65cd2eecc2b3038ce5a94aabb738c95"}
>
> # Insert a new document with same id
>
> mikael@couchdb:~$ curl -H "Content-Type: application/json" -d '{"_id":"1"}'
> -X PUT http://127.0.0.1:5998/test/1
> {"ok":true,"id":"1","rev":"1-967a00dff5e02add41819138abb3284d"}
>
> # Notice that couch gives it a rev number starting with "1-XX" and that it
> doesn't show up in the database.
>
> mikael@couchdb:~$ curl http://127.0.0.1:5998/test/_all_docs
> {"total_rows":0,"offset":0,"rows":[]}
>
>
> An other way to get the same behavior is to fiddle around with the rev
> number:
>
> # I have two newly created databases named "a" and "b"
>
> couchdb@couchdb:~$ curl http://127.0.0.1:5998/_all_dbs
> ["_users","a","b"]
>
> # Insert a document to database "a", just to get hold of a rev number
> (doesn't seem to work with random rev number, but I haven't looked in to
> that so much)
>
> couchdb@couchdb:~$ curl -H "Content-Type: application/json" -d
> '{"docs":[{"_id":"1"}]}' -X POST http://127.0.0.1:5998/a/_bulk_docs
> [{"ok":true,"id":"1","rev":"1-967a00dff5e02add41819138abb3284d"}]
>
> # Insert a document to database "b" with the same id and rev as the
> document from "a"
>
> couchdb@couchdb:~$ curl -H "Content-Type: application/json" -d
> '{"docs":[{"_id":"1", "_rev":"1-967a00dff5e02add41819138abb3284d"}]}' -X
> POST http://127.0.0.1:5998/b/_bulk_docs
> [{"ok":true,"id":"1","rev":"2-7051cbe5c8faecd085a3fa619e6e6337"}]
>
> # Delete the document in "b" (notice that the rev number is "2-XX")
>
> couchdb@couchdb:~$ curl -H "Content-Type: application/json" -d
> '{"docs":[{"_id":"1","_rev":"2-7051cbe5c8faecd085a3fa619e6e6337","_deleted":true}]}'
> -X POST http://127.0.0.1:5998/b/_bulk_docs
> [{"ok":true,"id":"1","rev":"3-7379b9e515b161226c6559d90c4dc49f"}]
>
> # Insert a document with the same id but without a rev number
>
> couchdb@couchdb:~$ curl -H "Content-Type: application/json" -d
> '{"docs":[{"_id":"1"}]}' -X POST http://127.0.0.1:5998/b/_bulk_docs
> [{"ok":true,"id":"1","rev":"1-967a00dff5e02add41819138abb3284d"}]
>
> # Notice that couch gives it a rev number starting with "1-XX" and that it
> doesn't show up in the database.
>
> couchdb@couchdb:~$ curl  http://127.0.0.1:5998/b/_all_docs
> {"total_rows":0,"offset":0,"rows":[]}
>
>
>
> Best regards
> Mikael H├Ągerbro

Mime
View raw message