aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mnesia/src/mnesia.erl
diff options
context:
space:
mode:
authorUlf Wiger <[email protected]>2015-11-10 15:41:16 +0100
committerDan Gudmundsson <[email protected]>2016-05-09 14:52:58 +0200
commit184175acbddd30e609a8411a04be29f78503619d (patch)
treec4ee308083f524ea94259fc0a00cdc73680a0b9d /lib/mnesia/src/mnesia.erl
parent7eec056d380377571a621030ab41f548ddf1a6e0 (diff)
downloadotp-184175acbddd30e609a8411a04be29f78503619d.tar.gz
otp-184175acbddd30e609a8411a04be29f78503619d.tar.bz2
otp-184175acbddd30e609a8411a04be29f78503619d.zip
mnesia_ext: Refactor record_validation code
Should maybe be moved to mnesia.erl and inlined?? Or is it used elsewhere?
Diffstat (limited to 'lib/mnesia/src/mnesia.erl')
-rw-r--r--lib/mnesia/src/mnesia.erl43
1 files changed, 15 insertions, 28 deletions
diff --git a/lib/mnesia/src/mnesia.erl b/lib/mnesia/src/mnesia.erl
index d0dc9eb13b..f34129268b 100644
--- a/lib/mnesia/src/mnesia.erl
+++ b/lib/mnesia/src/mnesia.erl
@@ -557,22 +557,16 @@ write(_Tid, _Ts, Tab, Val, LockKind) ->
abort({bad_type, Tab, Val, LockKind}).
write_to_store(Tab, Store, Oid, Val) ->
- case ?catch_val({Tab, record_validation}) of
- {RecName, Arity, Type}
- when tuple_size(Val) == Arity, RecName == element(1, Val) ->
- case Type of
- bag ->
- ?ets_insert(Store, {Oid, Val, write});
- _ ->
- ?ets_delete(Store, Oid),
- ?ets_insert(Store, {Oid, Val, write})
- end,
- ok;
- {'EXIT', _} ->
- abort({no_exists, Tab});
- _ ->
- abort({bad_type, Val})
- end.
+ {_, _, Type} = mnesia_lib:validate_record(Tab, Val),
+ Oid = {Tab, element(2, Val)},
+ case Type of
+ bag ->
+ ?ets_insert(Store, {Oid, Val, write});
+ _ ->
+ ?ets_delete(Store, Oid),
+ ?ets_insert(Store, {Oid, Val, write})
+ end,
+ ok.
delete({Tab, Key}) ->
delete(Tab, Key, write);
@@ -1549,16 +1543,9 @@ dirty_write(Tab, Val) ->
do_dirty_write(SyncMode, Tab, Val)
when is_atom(Tab), Tab /= schema, is_tuple(Val), tuple_size(Val) > 2 ->
- case ?catch_val({Tab, record_validation}) of
- {RecName, Arity, _Type}
- when tuple_size(Val) == Arity, RecName == element(1, Val) ->
- Oid = {Tab, element(2, Val)},
- mnesia_tm:dirty(SyncMode, {Oid, Val, write});
- {'EXIT', _} ->
- abort({no_exists, Tab});
- _ ->
- abort({bad_type, Val})
- end;
+ {_, _, _} = mnesia_lib:validate_record(Tab, Val),
+ Oid = {Tab, element(2, Val)},
+ mnesia_tm:dirty(SyncMode, {Oid, Val, write});
do_dirty_write(_SyncMode, Tab, Val) ->
abort({bad_type, Tab, Val}).
@@ -1610,8 +1597,8 @@ dirty_update_counter(Tab, Key, Incr) ->
do_dirty_update_counter(SyncMode, Tab, Key, Incr)
when is_atom(Tab), Tab /= schema, is_integer(Incr) ->
- case ?catch_val({Tab, record_validation}) of
- {RecName, 3, set} ->
+ case mnesia_lib:validate_key(Tab, Key) of
+ {RecName, 3, Type} when Type == set; Type == ordered_set ->
Oid = {Tab, Key},
mnesia_tm:dirty(SyncMode, {Oid, {RecName, Incr}, update_counter});
_ ->