0

We want to use Riak's Links to create a doubly linked list.

The algorithm for it is quite simple, I believe:

  1. Let 'N0' be the new element to insert
  2. Get the head of the list, including its 'next' link (N1)
  3. Set the 'previous' of N1 to be the N0.
  4. Set the 'next' of N0 to be N1
  5. Set the 'next' of the head of the list to be N0.

The problem that we have is that there is an obvious race condition here, because if 2 concurrent clients get the head of the list, one of the items will likely be 'lost'. Any way to avoid that?

Julien Genestoux
  • 31,046
  • 20
  • 66
  • 93

1 Answers1

2

Riak is an eventually consistent system when talking about CAP theorem.

Provided you set the bucket property allow_multi=true, if two concurrent clients get the head of the list then write, you will have sibling records. On your next read you'll receive multiple values (siblings) and will then have to resolve the conflict and write the result. Given that we don't have any sort of atomicity this will possibly lead to additional conflicts under heavy write concurrency as you attempt to update the linked objects. Not impossible to resolve, but definitely tricky.

You're probably better off simply serializing the entire list into a single object. This makes your conflict resolution much simpler.

Brian Roach
  • 76,169
  • 12
  • 136
  • 161