日期:2014-05-16  浏览次数:20432 次

mnesia的普通transaction写过程(二)写操作

上一篇博文介绍了mnesia的事务准备阶段,在其transaction上下文中执行了传入的函数,该函数为

fun() -> mnesia:write({user, me, 12345}) end

此后将继续分析。

mnesia_tm.erl

apply_fun(Fun, Args, Type) ->
? ? Result =?apply(Fun, Args),
? ? case?t_commit(Type)?of
do_commit ->
? ? ? ? ? ? {atomic, Result};
? ? ? ? do_commit_nested ->
? ? ? ? ? ? {nested_atomic, Result};
? ? ? ? {do_abort, {aborted, Reason}} ->
? ? ? ? ? ? {'EXIT', {aborted, Reason}};
? ? ? ? {do_abort, Reason} ->
? ? ? ? ? ? {'EXIT', {aborted, Reason}}
? ? end.
mnesia.erl
write(Val) when is_tuple(Val), tuple_size(Val) > 2 ->
? ? Tab = element(1, Val),
write(Tab, Val, write);
write(Tab, Val, LockKind) ->
? ? case get(mnesia_activity_state) of
{?DEFAULT_ACCESS, Tid, Ts} ->
? ?write(Tid, Ts, Tab, Val, LockKind);
{Mod, Tid, Ts} ->
? ?Mod:write(Tid, Ts, Tab, Val, LockKind);