Apache CouchDB vs CouchBaseLite: difference in revisions hashes

27 views
Skip to first unread message

Igor Ievsiukov

unread,
Oct 13, 2014, 3:22:51 PM10/13/14
to mobile-c...@googlegroups.com
Hi everyone,

I've noticed that having the same doc _id and content, Apache CouchDB and CouchBase Lite are generating different revision hashes. 

For example, freshly installed CouchDB 1.6.1 from Homebrew:

{"couchdb":"Welcome","uuid":"f2b1fdee5c482a9e273d062572369c5d","version":"1.6.1","vendor":{"version":"1.6.1-1","name":"Homebrew"}}
{"ok":true}
# curl -X PUT -H "Content-Type: application/json" http://127.0.0.1:5984/db1/doc1 -d '{"foo":"bar"}'
{"ok":true,"id":"doc1","rev":"1-4c6114c65e295552ab1019e2b046b10e"}
{"_id":"doc1","_rev":"1-4c6114c65e295552ab1019e2b046b10e","foo":"bar"}

(this is consistent on multiple different machines)

And this is LiteServ Community Edition:

{"vendor":{"name":"Couchbase Lite (Objective-C)","version":"1.0.2 (build 7)"},"couchdb":"Welcome","CouchbaseLite":"Welcome","version":"1
{"ok":true}
# curl -X PUT -H "Content-Type: application/json" http://127.0.0.1:59840/db1/doc1 -d '{"foo":"bar"}'
{"id":"doc1","rev":"1-aaa6c063924b64a141c98820efcc0022","ok":true}

(same valid for mobile version, consistent between iOS and Android)

As you can see, for the document with exactly the same _id and content, CouchDB generated "1-4c6114c65e295552ab1019e2b046b10e" and CBL has generated "1-aaa6c063924b64a141c98820efcc0022". Now, correct me if I'm wrong, but from my understanding, in this case, revision hashes must match, because:
 a) revision is a MD5 of a document and its' attachments; which are identical here
 b) replication will be messed up: we will have a conflict where it shouldn't be

Am I missing something here or having different revision hashes is normal for different implementations?

Many thanks in advance,
Igor

Jens Alfke

unread,
Oct 13, 2014, 7:12:22 PM10/13/14
to mobile-c...@googlegroups.com
On Oct 13, 2014, at 12:22 PM, Igor Ievsiukov <igor.ie...@gmail.com> wrote:

I've noticed that having the same doc _id and content, Apache CouchDB and CouchBase Lite are generating different revision hashes. 

This is true, but it's not really a problem.

 a) revision is a MD5 of a document and its' attachments; which are identical here

It's actually generated from the parent rev ID, the 'deleted' flag, and the JSON. But there are a lot of different ways to encode this information before generating an MD5, and CBL and CouchDB don't do it identically. In particular, (if I recall correctly) CouchDB doesn't digest the JSON but rather the serialized Erlang term that represents it; that's something CBL couldn't practically reproduce, so I didn't even try.

 b) replication will be messed up: we will have a conflict where it shouldn't be

This only happens in the case where two clients (one CBL, one CouchDB) make the exact same change to the same parent revision. The revisions they create will have identical contents but different revision IDs. This will be a conflict but one that's trivial to resolve. Note that one of those two revisions has to be created by CouchDB itself, i.e. by a direct PUT to CouchDB's REST API, not just using CouchDB as a replication server.

—Jens

Igor Ievsiukov

unread,
Oct 15, 2014, 8:38:25 AM10/15/14
to mobile-c...@googlegroups.com
Hi Jens,

Thank you for your reply.

(if I recall correctly) CouchDB doesn't digest the JSON but rather the serialized Erlang term that represents it;
yeah, in this case it will be impossible to generate rev same as in couchdb.

I do understand that this is quite a rare use-case, but I just got it randomly and was wandering if I'm doing something wrong.

Anyways, thanks again!

- Igor 
Reply all
Reply to author
Forward
0 new messages