[erlang-questions] mnesia dirty writes & race conditions

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Mon May 4 16:07:29 CEST 2015


On Mon, May 4, 2015 at 9:40 AM, Roberto Ostinelli <
roberto.ostinelli@REDACTED> wrote:

> However, I'd feel better in finding a way to guarantee the atomicity of
> the operation.


When you request atomicity of the operation, you are asking for
linearizability, which is a quite specific guarantee. You request that
there is some point in time, and once you go beyond that point, any read
will always see the new value and can't be stale (This is an informal
description, but the real linearizability guarantee has a fully formal
notion). Reads which overlap the point in time sees either the new or the
old value, but reads that come after the point in time will *always* see
the new value. This is the essential guarantee of atomicity/linearizability.

In the sense of CAP, you are now in CP land, as linearizability is strictly
in CP. This means you need coordination of some kind in order to solve it.
Your method of electing a leader is one, if done correctly (i.e., hi
consensus algorithms or distributed locking). The other one is to run a
mnesia-transaction, which almost gets you there[0].

But chances are you don't need linearizability for the operation in the
first place. And then, you can avoid having to coordinate as you may be
able to put yourself in AP instead. AP is typically much faster due to the
lack of coordination, but do see the work of e.g., Neha Narula (et.al.) for
counterexamples to this.

[0] I've argued before that mnesia is neither CP nor AP, and since you
can't be CA, mnesia isn't really a distributed system in the typical notion
of the word.


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


More information about the erlang-questions mailing list