日期:2014-05-16 浏览次数:20519 次
上一篇博文介绍了mnesia的写操作函数write完成的工作,其中涉及了锁请求过程,此后将继续分析。
mnesia_locker.erl
wlock(Tid, Store, Oid) ->
? ? wlock(Tid, Store, Oid, _CheckMajority = true).
wlock(Tid, Store, Oid, CheckMajority) ->
? ? {Tab, Key} = Oid,
? ? case need_lock(Store, Tab, Key, write) of
yes ->
? ?{Ns, Majority} = w_nodes(Tab),
? ?if CheckMajority ->
? ?check_majority(Majority, Tab, Ns);
? ? ? true ->
? ?ignore
? ?end,
? ?Op = {self(), {write, Tid, Oid}},
? ??ets_insert(Store, {{locks, Tab, Key}, write}),
? ?get_wlocks_on_nodes(Ns, Ns, Store, Op, Oid);
no when Key /= ?ALL, Tab /= ?GLOBAL ->
? ?[];
no ->
? ?element(2, w_nodes(Tab))
? ? end.