[erlang-questions] auto-syncing mnesia after a network split

David Mercer <>
Tue Dec 2 21:24:18 CET 2008


On Tuesday, December 02, 2008, Joel Reymont wrote:

> Imagine a bank account that's distributed across the split nodes,
> where a customer deposits money a 2 times and the deposits are split
> across the nodes. You'll pick up the latest deposit on one node and
> miss the other deposit.
> 
> I think you can overcome this programmatically, with a timestamp _and_
> a version number. You can have a version table per node with three
> columns: table name, vnum and timestamp. The rest of the tables would
> have just the vnum in their records.
> 
> When updating table T, you will first update the version table by
> storing the current time and bumping the vnum for the key T. You will
> then store the vnum in the record of table T that you are updating.
> 
> You will be able to find the split time by looking at the version
> tables and figuring out when the vnums started to diverge. You can
> then invoke a merge function that figures out, for example, how to
> merge a bunch of bank deposit transactions into a single balance.
> 
> You will know the vnum at split time and will only need to consider
> the transactions that happened after. Shouldn't be a lot of
> transactions for a short split time.
> 

> What do you think?

How do you handle unsynched clocks on the two nodes?

How about two different transactions that occur at the same time on the two
nodes right after the split?

And if an account with balance x before the split on one node has a balance
of x + d1 after a deposit, while the other node has balance x + d2 after
another deposit, all you have during the merge is the balances x + d1 and x
+ d2, and no way to identify d1 and d2 without knowing x.  Isn't this what
databases use transaction logs for, and if so, can we learn anything from
how they handle this situation?  Anyone have that expertise?

Cheers,

David




More information about the erlang-questions mailing list