[erlang-questions] Mnesia: dirty operations inside transactions

Håkan Mattsson hm@REDACTED
Tue Feb 22 15:48:01 CET 2011


On Tue, Feb 22, 2011 at 10:29 AM, Magnus Henoch
<magnus.henoch@REDACTED> wrote:
> Hi all,
>
> I've stumbled upon an apparent contradiction in the Mnesia user manual.
>
> Section 4.3, "Dirty operations", says:
>
> "Even if the following [dirty] functions are executed inside a transaction no
> locks will be acquired."
> http://erlang.org/doc/apps/mnesia/Mnesia_chap4.html#id71370
>
> But section 4.6, "Nested transactions", says:
>
> "It is also possible to mix different activity access contexts while nesting,
> but the dirty ones (async_dirty,sync_dirty and ets) will inherit the transaction
> semantics if they are called inside a transaction and thus it will grab locks
> and use two or three phase commit."
>
> http://erlang.org/doc/apps/mnesia/Mnesia_chap4.html#id72122
>
> So do the dirty functions grab locks or not?

Sometimes. ;-)

> Is there a difference between calling dirty_write etc directly on one hand,

Yes, mnesia:dirty_write and friends does never grab locks

> and using mnesia:sync_dirty/1 or mnesia:activity/2 on the other hand?

while mnesia:write and friends can grab locks depending on the activity
context. If the activity is a transaction or if it is enclosed in a transaction
(such as a sync_dirty nested in a transaction) mnesia:write etc will grab
locks. Otherwise they will not grab locks.

/Håkan

> Regards,
> Magnus


More information about the erlang-questions mailing list