incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Shorin <kxe...@gmail.com>
Subject Re: Is the revision field deterministic?
Date Tue, 08 Apr 2014 15:34:57 GMT
On Tue, Apr 8, 2014 at 7:01 PM, Jens Alfke <jens@couchbase.com> wrote:
> On Apr 8, 2014, at 7:31 AM, Daniel Gonzalez <gonvaled@gonvaled.com> wrote:
>
>> Ok, but does mean it is indeed related to the document content, so a
>> different content would produce a different revision number.
>
> Yes. It’s an MD5 (?) digest computed from the document JSON.

It's an MD5 digest from Erlang representation (proplist) of JSON
document, not from JSON document itself.

>> And just curious: what does "the same content mean"? Is a different
>> re-ordering of the json fields still passing the comparisson check?

Yes, order matters.

{"foo": 0, "bar": 1} would be represented internally as [{<<"foo">>,
0}, {<<"bar">>, 1}]
while
{"bar": 1, "foo": 0} would be [{<<"bar">>, 1}, {<<"foo">>, 0}]

Logically objects are the same, but different representation produces
different digest.

As for JavaScript, it's by accident preserves object's fields order
during serialization to JSON, so by the same accident it gives the
same internal representation and the same digest for CouchDB. With
Python or Ruby this trick wouldn't work unless underlying JSON library
wouldn't produce determinate output (for instance, by sorting object's
keys).

P.S.

> Couchbase Lite computes rev IDs based on a canonical encoding[2] of the JSON that will
always generate the same result regardless of serialization differences. It won’t be the
same result arrived at by CouchDB, though.

Jens, is that was another uncanny attempt to adv. unrelated product
without providing relevant information? These actions only confuses
people forcing them thinking that Couchbase and CouchDB are the
similar products while they don't.

--
,,,^..^,,,

Mime
View raw message