We want to use Riak's Links to create a doubly linked list.
The algorithm for it is quite simple, I believe:
- Let 'N0' be the new element to insert
- Get the head of the list, including its 'next' link (N1)
- Set the 'previous' of N1 to be the N0.
- Set the 'next' of N0 to be N1
- 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?