ConvergentReplicatedData Types
View Slide
@vanstee[email protected]Patrick Van Stee
“Structuringdata so conflictresolution isautomatic”
DynamoTrade consistencyfor availability andpartition tolerance
Node 1 Node 2{ a: “200” } { a: “-3000” }:(
Node 1 Node 2{ a: “200” } { a: “-3000” }{ a: “200”, a: “-3000” }Riak
CRDT•Counter•Set•Graph•List•Tree
Counter•Can only be increased•Merge: use largest value
Chat RoomKarmaFault-TolerantDistributed
Serious Business{ SB[PVS]: 0}Serious Coding{ SB[PVS]: 1} # PVS++{ SC[PVS]: 0}{ SC[PVS]: 5} # PVS += 5{ SB[PVS]: 2} # PVS++Merge{ SB[PVS]: 2, SC[PVS]: 5} { SB[PVS]: 1, SC[PVS]: 5}{ SB[PVS]: 2, SC[PVS]: 5}{ PVS: 7}
What aboutdecrements?Use separate countersfor positive and negative.Take the difference forthe result.
Serious Business{ SB[PVS+]: 0, SB[PVS-]: 0 }Serious Coding{ SB[PVS+]: 1, SB[PVS-]: 0 } # PVS++{ SB[PVS+]: 0, SB[PVS-]: 0 }{ SB[PVS+]: 5, SB[PVS-]: 0 } # PVS += 5{ SB[PVS+]: 1, SB[PVS-]: 1 } # PVS--Merge{ PVS+: 6, PVS-: 1 } { PVS+: 6, PVS-: 0 }{ PVS+: 6, PVS-: 1 }{ PVS: 5 }
Set•Can only be added to•Merge: take the union
Serious Business{ PVS: [ ] }Serious Coding{ PVS: [] } { PVS: [] }{ PVS: [ ] }Merge{ PVS: [ , ] }{ PVS: [ , ] }{ PVS: [ , , ] }{ PVS: [ , , ] }
Hold on, Canwe removestuff?Use separate sets for addedand removed elements.
Serious Business{ PVS+: [ ], PVS-: [] }Serious Coding{ PVS+: [], PVS-: [] } { PVS+: [], PVS-: [] }{ PVS+: [ ], PVS-: [] }Merge{ PVS+: [ , ], PVS-: [ ] }{ PVS+: [ ], PVS-: [ ] }{ PVS+: [ , ], PVS-: [] }{ PVS+: [ , ], PVS-: [ ] }{ PVS: [ ] }
But wait,we can onlyremove once?
U-Set•Append unique valuesto all set members•Garbage collectionbecomes an issue
basho/riak_dtDemo
Use Cases•Like button•Page Views•Shopping Cart
Reference•INRIA paper•basho/riak_dt•RICON talk
BeginningRuby on RailsCoursebignerdranch.com/classes/beginning_ruby_on_rails