dominictarr / crdt

Commutative Replicated Data Types for easy collaborative/distributed systems.
MIT License
836 stars 43 forks source link

matching UUID and ID? #9

Closed bmeck closed 12 years ago

bmeck commented 12 years ago

Given something akin to the following:

Doc=require('crdt').Doc;
dns_a = new Doc();
dns_b = new Doc();

dns_a.add({id:'?',a:1, b:3});
dns_b.add({id:'?',a:2,b:2});

Is there a guaranteed history order when the update UUIDs match the same point in time (across a network partition)? Will it pick a random UUID between the 2?

dominictarr commented 12 years ago

if the timestamp is equal (highly unlikely, unless adding data very rapidly) then the tie is broken by sorting on origin id.

dns_a.add({id:ID,a:1, b:3});

Here, ID only refers to that record, update with the same id will overwrite the previous, depending on which was most recent. (depends on network time accuracy being more fine grained than the update frequency) this is not a problem if each node is only updating it's own records though.

the timestamp is not exposed to the user, but doc.id is the origin id. you can set that manually when you call new Doc(id)

bmeck commented 12 years ago

Thanks, may add a pr tonight documenting that.

dominictarr commented 12 years ago

sweet!