MongoDB Races, Locks, and Transactions

William Reade william.reade at canonical.com
Thu Jun 28 00:02:18 UTC 2012


On Thu, 2012-06-28 at 00:47 +0200, Aram Hăvărneanu wrote:
> Hello team,
> 
> Our current mstate code is racy. For example, a service might dissapear
> before we try to add a service unit to it. One way of dealing with these
> issues is with transactions. As you well know, MongoDB does not have
> transactions. While we could implement transactions using multi-phase
> commits (http://cookbook.mongodb.org/patterns/perform-two-phase-commits/),
> I propose a much simpler mechanism to deal with our problems.
> 
> We add an integer version field to our documents. This field is set
> to -1 for every relevant document before any operation that involves
> multiple queries. After the series of queries is completed, the field is
> incremented from the value it had before we set it to -1. MongoDB has
> a compare-and-swap primitive that allows us to do this set/increment
> atomically.

What happens when the network falls over partway through the series of
changes? I don't see how this approach helps us in that case: it seems
we'd end up stuck with inconsistent state, and with no means of
recovery. Am I missing something?


Cheers
William




More information about the Juju-dev mailing list