“原始”脏操作和mnesia中的脏操作之间有什么区别:async_transaction

时间:2012-11-09 20:49:49

标签: erlang mnesia

在传递给mnesia:async_dirty()的函数中执行的一系列mnesia:dirty_命令与执行“raw”的那些相同事务之间有什么区别?

即,做:

之间有什么区别吗?
mnesia:dirty_write({table, Rec1}),
mnesia:dirty_write({table, Rec1}),
mnesia:dirty_write({table, Rec1})

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

   mnesia:async_dirty(F)

由于

1 个答案:

答案 0 :(得分:-1)

让我们首先引用async_dirty上下文中的用户指南:

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.

您提供的两个选项将以相同的方式执行。但是,当您从选项1中的fun执行脏函数时,每个函数都是对mnesia的单独调用。使用async_dirty,将捆绑3个呼叫,并且mnesia将只等到本地节点上的3个完成返回。然而,这两者的行为在mnesia多节点集群中可能不同。做一些测试:))