日期:2014-05-16 浏览次数:20441 次
上一篇博文介绍了mnesia的事务提交准备过程,为每个事务参与结点构造了其提交结构commit,下面将进入到提交过程中,此后将继续分析。
?
mnesia_tm.erl
?
multi_commit(sym_trans, _Maj = [], Tid, CR, Store) ->
? ? {DiscNs, RamNs} = commit_nodes(CR, [], []),
? ? Pending = mnesia_checkpoint:tm_enter_pending(Tid, DiscNs, RamNs),
? ? ?ets_insert(Store, Pending),
?
? ? {WaitFor, Local} = ask_commit(sym_trans, Tid, CR, DiscNs, RamNs),
? ? {Outcome, []} = rec_all(WaitFor, Tid, do_commit, []),
? ? ?eval_debug_fun({?MODULE, multi_commit_sym},
? ?[{tid, Tid}, {outcome, Outcome}]),
? ? rpc:abcast(DiscNs -- [node()], ?MODULE, {Tid, Outcome}),
? ? rpc:abcast(RamNs -- [node()], ?MODULE, {Tid, Outcome}),
? ? case Outcome of
do_commit ->
? ?mnesia_recover:note_decision(Tid, committed),
? ?do_dirty(Tid, Local),
? ?mnesia_locker:release_tid(Tid),
? ??MODULE ! {delete_transaction, Tid};
{do_abort, _Reason} ->
? ?mnesia_recover:note_decision(Tid, aborted)
? ? end,
? ? ?eval_debug_fun({?MODULE, multi_commit_sym, post},
? ?[{tid, Tid}, {outcome, Outcome}]),
Outcome;
commit_nodes([C | Tail], AccD, AccR)
? ? ? ? when C#commit.disc_copies == [],
? ? ? ? ? ? ?C#commit.disc_only_copies ?== [],
? ? ? ? ? ? ?C#commit.schema_ops == [] ->
? ? commit_nodes(Tail, AccD, [C#commit.node | AccR]);
commit_nodes([C | Tail], AccD, AccR) ->
? ? commit_nodes(Tail, [C#commit.node | AccD], AccR);
commit_nodes([], AccD, AccR) ->
? ? {AccD, AccR}.
取出所有参与事务的结点,这实质上等同于where_to_commit属性记录的所有结点。