[erlang-questions] Couple of questions about mnesia locking
Ulf Wiger
ulf.wiger@REDACTED
Sun Apr 5 09:27:50 CEST 2009
Hynek Vychodil wrote:
> mnesia uses optimistic locking. When NodeB's write is called than
> transaction fails and is restarted. This is why mneasia transaction
> should not contain side-effects. See mnesia manual for details.
Actually, no. Mnesia waits for the locks needed before
proceeding, and keeps the locks until it either aborts
or commits. However, in any locking environment, one
must guard against deadlocks. If the lock manager is
centralized, it's possible to maintain a wait-for graph,
which is scanned each time a new lock is requested.
This approach doesn't scale in a distributed setting,
so an alternative approach, called "deadlock prevention",
is to allow only unidirectional dependencies (for some
definition of unidirectional - e.g. from smaller to
larger pids.) If a lock is requested that would create
a dependency in the other direction, one of the
transactions involved is restarted. This is why mnesia
transactions can restart sometimes.
BR,
Ulf W
--
Ulf Wiger
CTO, Erlang Training & Consulting Ltd
http://www.erlang-consulting.com
More information about the erlang-questions
mailing list