aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartlomiej Puzon <[email protected]>2012-06-18 16:16:00 -0700
committerBartlomiej Puzon <[email protected]>2012-06-18 16:16:00 -0700
commit0fcdb6fdd38291072dd130cf4362ea5e8f3d1717 (patch)
tree08512bcff4587baae92885928d10d4654d85c66a
parent8490cb6328da880119dbc1eb92d3b439a2c5f34a (diff)
downloadotp-0fcdb6fdd38291072dd130cf4362ea5e8f3d1717.tar.gz
otp-0fcdb6fdd38291072dd130cf4362ea5e8f3d1717.tar.bz2
otp-0fcdb6fdd38291072dd130cf4362ea5e8f3d1717.zip
Prevent index from being corrupted if a nonexistent item is deleted
We have to ensure that we actually delete the last object with a given (key, index) pair before removing the index.
-rw-r--r--lib/mnesia/src/mnesia_index.erl6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/mnesia/src/mnesia_index.erl b/lib/mnesia/src/mnesia_index.erl
index 61210d7e55..37989a1958 100644
--- a/lib/mnesia/src/mnesia_index.erl
+++ b/lib/mnesia/src/mnesia_index.erl
@@ -120,9 +120,9 @@ del_object_bag(Tab, Key, Obj, Pos, Ixt, undefined) ->
IxKey = element(Pos, Obj),
Old = [X || X <- mnesia_lib:db_get(Tab, Key), element(Pos, X) =:= IxKey],
del_object_bag(Tab, Key, Obj, Pos, Ixt, Old);
-%% If Tab type is bag we need remove index identifier if Tab
-%% contains less than 2 elements.
-del_object_bag(_Tab, Key, Obj, Pos, Ixt, Old) when length(Old) < 2 ->
+%% If Tab type is bag we need remove index identifier if the object being
+%% deleted was the last one
+del_object_bag(_Tab, Key, Obj, Pos, Ixt, Old) when Old =:= [Obj] ->
del_ixes(Ixt, [Obj], Pos, Key);
del_object_bag(_Tab, _Key, _Obj, _Pos, _Ixt, _Old) -> ok.