Storing doubly linked lists in Riak without a race condition? -
we want use riak's links create doubly linked list.
the algorithm quite simple, believe:
- let 'n0' new element insert
- get head of list, including 'next' link (n1)
- set 'previous' of n1 n0.
- set 'next' of n0 n1
- set 'next' of head of list n0.
the problem have there obvious race condition here, because if 2 concurrent clients head of list, 1 of items 'lost'. way avoid that?
riak consistent system when talking cap theorem.
provided set bucket property allow_multi=true
, if 2 concurrent clients head of list write, have sibling records. on next read you'll receive multiple values (siblings) , have resolve conflict , write result. given don't have sort of atomicity possibly lead additional conflicts under heavy write concurrency attempt update linked objects. not impossible resolve, tricky.
you're better off serializing entire list single object. makes conflict resolution much simpler.
Comments
Post a Comment