incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Leddy <m...@loop.com.br>
Subject Having problems with conflict resolution
Date Mon, 10 Jan 2011 16:18:57 GMT
Hello,

I have a situation where the same document can come from several sources
and I have written a script (in ruby) which effectively merges the
information in all conflicting documents (deletes the originals) and
inserts the new merged document.

Everything seemed fine until I observed that sometimes the newly inserted
document remained deleted..... 

On further investigation I discovered that I was (by design) merging the
documents in a deterministic way and it was possible that if I was merging
documents A + B + C giving A ie: document A already has all the
information contained in documents A & B & C.

Since i was deleting A and then subsequently inserting essentially the same
document it remained deleted even though the bulk_docs API was indicating a
successful insertion.

I am using a recent 1.0.x branch. Here is the essence of what is happening
using the same API calls:

# create a database
curl -X PUT 127.0.0.1:5984/bulk_docs
{"ok":true}

# insert a doc 'mike'
curl -X POST -H 'Content-type: application/json' 'localhost:5984/bulk_docs/_bulk_docs' -d
'{"all_or_nothing":true,"docs":[{"_id":"same", "name":"mike"}]}'
[{"id":"same","rev":"1-d6246810df84e21f7611601d0cceccbf"}]

# insert another doc 'john' with same id
curl -X POST -H 'Content-type: application/json' 'localhost:5984/bulk_docs/_bulk_docs' -d
'{"all_or_nothing":true,"docs":[{"_id":"same", "name":"john"}]}'
[{"id":"same","rev":"1-ec562a018012e70bbf8da7f6f58970d7"}]

# 'john' is the winning conflict
curl 'localhost:5984/bulk_docs/same'
{"_id":"same","_rev":"1-ec562a018012e70bbf8da7f6f58970d7","name":"john"}

# delete 'john'
curl -X DELETE 'localhost:5984/bulk_docs/same?rev=1-ec562a018012e70bbf8da7f6f58970d7'
{"ok":true,"id":"same","rev":"2-1dae8400f3e20ab34b845e855ba6dc85"}

# delete 'mike'
curl -X DELETE 'localhost:5984/bulk_docs/same?rev=1-d6246810df84e21f7611601d0cceccbf'
{"ok":true,"id":"same","rev":"2-db780681eced993484c7f171ab7f599c"}

# none left
curl 'localhost:5984/bulk_docs/same'
{"error":"not_found","reason":"deleted"}

# insert 'mike' again
curl -X POST -H 'Content-type: application/json' 'localhost:5984/bulk_docs/_bulk_docs' -d
'{"all_or_nothing":true,"docs":[{"_id":"same", "name":"mike"}]}'
[{"id":"same","rev":"1-d6246810df84e21f7611601d0cceccbf"}]

# ouch !!!!!
curl 'localhost:5984/bulk_docs/same'
{"error":"not_found","reason":"deleted"}

Since I have the conflict resolution script working on all nodes I want
the result to be deterministic so as to be sure that all nodes calculate 
the same result and produce revisions that are the same....... always
converging on exactly the same result.

Any insights ?

Regards,

Mike


Mime
View raw message