What is the difference between "raw" dirty operations, and dirty operations within mnesia:async_transaction
Asked Answered
E

1

6

What is the difference between a series of mnesia:dirty_ commands executed within a function passed to mnesia:async_dirty() and those very same transactions executed "raw"?

I.e., is there any difference between doing:

mnesia:dirty_write({table, Rec1}),
mnesia:dirty_write({table, Rec1}),
mnesia:dirty_write({table, Rec1})

and

F = fun() ->
        mnesia:dirty_write({table, Rec1}),
        mnesia:dirty_write({table, Rec1}),
        mnesia:dirty_write({table, Rec1})
   end,

   mnesia:async_dirty(F)

Thanks

Electroform answered 9/11, 2012 at 20:49 Comment(0)
C
0

Lets first quote the Users' Guide on async_dirty context:

By passing the same "fun" as argument to the function 
mnesia:async_dirty(Fun [, Args]) it will be performed in dirty context.
The function calls will be mapped to the corresponding dirty functions.
This will still involve logging, replication and subscriptions but there will be
no locking, local transaction storage or commit protocols involved. Checkpoint
retainers will be updated but will be updated "dirty". Thus, they will be updated
asynchronously. The functions will wait for the operation to be performed on one
node but not the others. If the table resides locally no waiting will occur.

The two options you have provided will be executed the same way. However, when you execute the dirty functions out of the fun as in option one, each one is a separate call into mnesia. With async_dirty, the 3 calls will be bundled and mnesia will only wait until the 3 are completed on the local node to return.
However, the behavior of these two may differ in a mnesia multi-node cluster. Do some tests :)

Chiffonier answered 10/11, 2012 at 9:20 Comment(4)
What do you mean "... behavior of these two may differ in a multi-node cluster", do you mean you don't know if it will differ, you know it will differ but don't know how, or you know but aren't telling me?Electroform
i know they will differ, but don't know specifically how :)Chiffonier
Downvoted this because I have the same question and this answer is inadequate. If you read the async_dirty documentation it says: "As for normal mnesia:dirty_* operations, the operations are performed semi-asynchronously.". What does semi-async mean here?Guitar
Another note from erlang.org/doc/apps/mnesia/Mnesia_chap4.html. """ The function mnesia:dirty_* always executes with async_dirty semantics regardless of which activity access contexts that are started. It can even start contexts without any enclosing activity access context."""Guitar

© 2022 - 2024 — McMap. All rights reserved.