[erlang-questions] mnesia dirty writes & race conditions

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Sun May 3 20:21:26 CEST 2015


On Sun, May 3, 2015 at 6:12 PM, Roberto Ostinelli <roberto@REDACTED>
wrote:

> Dear list,
> What is (or are) the expected outcome(s) of a race condition during mnesia
> dirty writes on a table of type `set`?
>

The lower bound is "whatever ETS gives you" which means that writes to a
row is atomic, on a single node. The last writer wins. If two nodes writes
to the same record at the same time, I'm not sure you have any guarantees
about what you read on other nodes.

In other words, I wouldn't expect any guarantee, in particular writing {K,
V1} on node1 and {K, V2} on node2 could result in write order {K, V1} ->
{K, V2} on one node and {K, V2} -> {K, V1} on another node. If you want
that guarantee, you should run a transaction.

The problem can often be avoided because if you know a priori that your key
K is under your sole responsibility, then a dirty_write is safe insofar
noone else can change it, and you control the writing order, which means
everyone eventually ends up with the same value.

-- 
J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150503/b00054cb/attachment.htm>


More information about the erlang-questions mailing list