aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mnesia/src
diff options
context:
space:
mode:
authorUlf Wiger <[email protected]>2010-12-13 08:08:46 +0100
committerHenrik Nord <[email protected]>2011-05-16 11:00:28 +0200
commit5309d521c394aa7ca1feb679dbda6333a3cb4873 (patch)
treeac1153d54690c7bfb9c42ca9b29cc33ad804405a /lib/mnesia/src
parent38eef7af0f8bc1d2d152cefb8df1e1303ddcac45 (diff)
downloadotp-5309d521c394aa7ca1feb679dbda6333a3cb4873.tar.gz
otp-5309d521c394aa7ca1feb679dbda6333a3cb4873.tar.bz2
otp-5309d521c394aa7ca1feb679dbda6333a3cb4873.zip
check majority for sticky locks
Diffstat (limited to 'lib/mnesia/src')
-rw-r--r--lib/mnesia/src/mnesia_locker.erl18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/mnesia/src/mnesia_locker.erl b/lib/mnesia/src/mnesia_locker.erl
index 9822dfd116..2025a2ab37 100644
--- a/lib/mnesia/src/mnesia_locker.erl
+++ b/lib/mnesia/src/mnesia_locker.erl
@@ -689,6 +689,7 @@ w_nodes(Tab) ->
%% only take a write lock if we see a majority of the
%% nodes.
+
check_majority(true, Tab, HaveNs) ->
check_majority(Tab, HaveNs);
check_majority(false, _, _) ->
@@ -732,6 +733,7 @@ sticky_lock(Tid, Store, {Tab, Key} = Oid, Lock) ->
end.
do_sticky_lock(Tid, Store, {Tab, Key} = Oid, Lock) ->
+ sticky_check_majority(Lock, Tab),
?MODULE ! {self(), {test_set_sticky, Tid, Oid, Lock}},
N = node(),
receive
@@ -761,6 +763,22 @@ do_sticky_lock(Tid, Store, {Tab, Key} = Oid, Lock) ->
dirty_sticky_lock(Tab, Key, [N], Lock)
end.
+sticky_check_majority(read, _) ->
+ ok;
+sticky_check_majority(write, Tab) ->
+ case ?catch_val({Tab, majority}) of
+ true ->
+ HaveNodes = val({Tab, where_to_write}),
+ case mnesia_lib:have_majority(Tab, HaveNodes) of
+ true ->
+ ok;
+ false ->
+ mnesia:abort({no_majority, Tab})
+ end;
+ _ ->
+ ok
+ end.
+
not_stuck(Tid, Store, Tab, _Key, Oid, _Lock, N) ->
rlock(Tid, Store, {Tab, ?ALL}), %% needed?
wlock(Tid, Store, Oid), %% perfect sync