aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mnesia
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mnesia')
-rw-r--r--lib/mnesia/doc/src/Mnesia_chap3.xmlsrc2
-rw-r--r--lib/mnesia/doc/src/Mnesia_chap5.xmlsrc5
-rw-r--r--lib/mnesia/doc/src/notes.xml23
-rw-r--r--lib/mnesia/src/Makefile5
-rw-r--r--lib/mnesia/src/mnesia.app.src7
-rw-r--r--lib/mnesia/src/mnesia.erl312
-rw-r--r--lib/mnesia/src/mnesia.hrl7
-rw-r--r--lib/mnesia/src/mnesia_app.erl41
-rw-r--r--lib/mnesia/src/mnesia_checkpoint.erl2
-rw-r--r--lib/mnesia/src/mnesia_controller.erl4
-rw-r--r--lib/mnesia/src/mnesia_event.erl2
-rw-r--r--lib/mnesia/src/mnesia_frag.erl76
-rw-r--r--lib/mnesia/src/mnesia_frag_old_hash.erl133
-rw-r--r--lib/mnesia/src/mnesia_kernel_sup.erl3
-rw-r--r--lib/mnesia/src/mnesia_lib.erl16
-rw-r--r--lib/mnesia/src/mnesia_monitor.erl4
-rw-r--r--lib/mnesia/src/mnesia_schema.erl22
-rw-r--r--lib/mnesia/src/mnesia_snmp_sup.erl43
-rw-r--r--lib/mnesia/src/mnesia_sup.erl33
-rw-r--r--lib/mnesia/test/ext_test.erl4
-rw-r--r--lib/mnesia/test/mnesia_evil_backup.erl2
-rw-r--r--lib/mnesia/vsn.mk2
22 files changed, 427 insertions, 321 deletions
diff --git a/lib/mnesia/doc/src/Mnesia_chap3.xmlsrc b/lib/mnesia/doc/src/Mnesia_chap3.xmlsrc
index 8f1a4366ee..ffda739dfa 100644
--- a/lib/mnesia/doc/src/Mnesia_chap3.xmlsrc
+++ b/lib/mnesia/doc/src/Mnesia_chap3.xmlsrc
@@ -348,7 +348,7 @@ skeppet %<input>erl -sname b -mnesia dir '"/ldisc/scratch/Mnesia.company"'</inpu
<p>If the startup procedure fails, the function
<seealso marker="mnesia#start/0">mnesia:start()</seealso>
returns the cryptic tuple
- <c>{error,{shutdown, {mnesia_sup,start,[normal,[]]}}}</c>.
+ <c>{error,{shutdown, {mnesia_sup,start_link,[normal,[]]}}}</c>.
To get more information about the start failure, use
command-line arguments <c>-boot start_sasl</c> as argument to
the <c>erl</c> script.</p>
diff --git a/lib/mnesia/doc/src/Mnesia_chap5.xmlsrc b/lib/mnesia/doc/src/Mnesia_chap5.xmlsrc
index a83d1d77d2..62759c624b 100644
--- a/lib/mnesia/doc/src/Mnesia_chap5.xmlsrc
+++ b/lib/mnesia/doc/src/Mnesia_chap5.xmlsrc
@@ -362,11 +362,6 @@ ok
<seealso marker="mnesia_frag_hash">mnesia_frag_hash</seealso>
callback behavior. This property can explicitly be set at
table creation. Default is <c>mnesia_frag_hash</c>.</p>
- <p>Older tables, that were created before the concept of
- user-defined hash modules was introduced, use module
- <c>mnesia_frag_old_hash</c> to be backwards compatible.
- <c>mnesia_frag_old_hash</c> still uses the poor
- deprecated function <c>erlang:hash/1</c>.</p>
</item>
<tag><c>{hash_state, Term}</c></tag>
<item>
diff --git a/lib/mnesia/doc/src/notes.xml b/lib/mnesia/doc/src/notes.xml
index 9f59759cb6..3ca4026190 100644
--- a/lib/mnesia/doc/src/notes.xml
+++ b/lib/mnesia/doc/src/notes.xml
@@ -4,7 +4,7 @@
<chapter>
<header>
<copyright>
- <year>1996</year><year>2016</year>
+ <year>1996</year><year>2017</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
@@ -39,7 +39,26 @@
thus constitutes one section in this document. The title of each
section is the version number of Mnesia.</p>
- <section><title>Mnesia 4.14.3</title>
+ <section><title>Mnesia 4.15</title>
+
+ <section><title>Improvements and New Features</title>
+ <list>
+ <item>
+ <p>
+ Removed the wrapping of select continuations in extension
+ plugin handling. This might require the user to rewrite
+ user backend plugin if used.</p>
+ <p>
+ *** POTENTIAL INCOMPATIBILITY ***</p>
+ <p>
+ Own Id: OTP-14039</p>
+ </item>
+ </list>
+ </section>
+
+</section>
+
+<section><title>Mnesia 4.14.3</title>
<section><title>Fixed Bugs and Malfunctions</title>
<list>
diff --git a/lib/mnesia/src/Makefile b/lib/mnesia/src/Makefile
index 08a00e6aba..7d316df263 100644
--- a/lib/mnesia/src/Makefile
+++ b/lib/mnesia/src/Makefile
@@ -1,7 +1,7 @@
#
# %CopyrightBegin%
#
-# Copyright Ericsson AB 1996-2016. All Rights Reserved.
+# Copyright Ericsson AB 1996-2017. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -43,6 +43,7 @@ RELSYSDIR = $(RELEASE_PATH)/lib/mnesia-$(VSN)
# ----------------------------------------------------
MODULES= \
mnesia \
+ mnesia_app \
mnesia_backend_type \
mnesia_backup \
mnesia_bup \
@@ -54,7 +55,6 @@ MODULES= \
mnesia_ext_sup \
mnesia_frag \
mnesia_frag_hash \
- mnesia_frag_old_hash \
mnesia_index \
mnesia_kernel_sup \
mnesia_late_loader \
@@ -67,7 +67,6 @@ MODULES= \
mnesia_registry \
mnesia_schema\
mnesia_snmp_hook \
- mnesia_snmp_sup \
mnesia_subscr \
mnesia_sup \
mnesia_sp \
diff --git a/lib/mnesia/src/mnesia.app.src b/lib/mnesia/src/mnesia.app.src
index 006ad4bac1..6b49fc6c88 100644
--- a/lib/mnesia/src/mnesia.app.src
+++ b/lib/mnesia/src/mnesia.app.src
@@ -3,6 +3,7 @@
{vsn, "%VSN%"},
{modules, [
mnesia,
+ mnesia_app,
mnesia_backend_type,
mnesia_backup,
mnesia_bup,
@@ -14,7 +15,6 @@
mnesia_ext_sup,
mnesia_frag,
mnesia_frag_hash,
- mnesia_frag_old_hash,
mnesia_index,
mnesia_kernel_sup,
mnesia_late_loader,
@@ -27,7 +27,6 @@
mnesia_registry,
mnesia_schema,
mnesia_snmp_hook,
- mnesia_snmp_sup,
mnesia_subscr,
mnesia_sup,
mnesia_sp,
@@ -49,7 +48,5 @@
mnesia_tm
]},
{applications, [kernel, stdlib]},
- {mod, {mnesia_sup, []}},
+ {mod, {mnesia_app, []}},
{runtime_dependencies, ["stdlib-2.0","kernel-3.0","erts-7.0"]}]}.
-
-
diff --git a/lib/mnesia/src/mnesia.erl b/lib/mnesia/src/mnesia.erl
index 34efeca4fa..3b771e8c5b 100644
--- a/lib/mnesia/src/mnesia.erl
+++ b/lib/mnesia/src/mnesia.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1996-2016. All Rights Reserved.
+%% Copyright Ericsson AB 1996-2017. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -138,6 +138,36 @@
-include("mnesia.hrl").
-import(mnesia_lib, [verbose/2]).
+-type create_option() ::
+ {'access_mode', 'read_write' | 'read_only'} |
+ {'attributes', [atom()]} |
+ {'disc_copies', [node()]} |
+ {'disc_only_copies', [node]} |
+ {'index', [index_attr()]} |
+ {'load_order', non_neg_integer()} |
+ {'majority', boolean()} |
+ {'ram_copies', [node()]} |
+ {'record_name', atom()} |
+ {'snmp', SnmpStruct::term()} |
+ {'storage_properties', [{Backend::module(), [BackendProp::_]}]} |
+ {'type', 'set' | 'ordered_set' | 'bag'} |
+ {'local_content', boolean()}.
+
+-type t_result(Res) :: {'atomic', Res} | {'aborted', Reason::term()}.
+-type activity() :: 'ets' | 'async_dirty' | 'sync_dirty' | 'transaction' | 'sync_transaction' |
+ {'transaction', Retries::non_neg_integer()} |
+ {'sync_transaction', Retries::non_neg_integer()}.
+-type table() :: atom().
+-type storage_type() :: 'ram_copies' | 'disc_copies' | 'disc_only_copies'.
+-type index_attr() :: atom() | non_neg_integer().
+-type write_locks() :: 'write' | 'sticky_write'.
+-type read_locks() :: 'read'.
+-type lock_kind() :: write_locks() | read_locks().
+-type select_continuation() :: term().
+-type snmp_struct() :: [{atom(), snmp_type() | tuple_of(snmp_type())}].
+-type snmp_type() :: 'fix_string' | 'string' | 'integer'.
+-type tuple_of(_T) :: tuple().
+
-define(DEFAULT_ACCESS, ?MODULE).
%% Select
@@ -196,7 +226,7 @@ e_has_var(X, Pos) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Start and stop
-
+-spec start() -> 'ok' | {'error', term()}.
start() ->
start([]).
@@ -216,6 +246,7 @@ start_() ->
{error, R}
end.
+-spec start([{Option::atom(), Value::_}]) -> 'ok' | {'error', term()}.
start(ExtraEnv) when is_list(ExtraEnv) ->
case mnesia_lib:ensure_loaded(?APPLICATION) of
ok ->
@@ -238,6 +269,7 @@ patched_start([Head | _]) ->
patched_start([]) ->
start_().
+-spec stop() -> 'stopped' | {'error', term()}.
stop() ->
case application:stop(?APPLICATION) of
ok -> stopped;
@@ -245,6 +277,7 @@ stop() ->
Other -> Other
end.
+-spec change_config(Config::atom(), Value::_) -> ok | {error, term()}.
change_config(extra_db_nodes, Ns) when is_list(Ns) ->
mnesia_controller:connect_nodes(Ns);
change_config(dc_dump_limit, N) when is_number(N), N > 0 ->
@@ -273,6 +306,7 @@ kill() ->
ms() ->
[
mnesia,
+ mnesia_app,
mnesia_backup,
mnesia_bup,
mnesia_checkpoint,
@@ -282,7 +316,6 @@ ms() ->
mnesia_loader,
mnesia_frag,
mnesia_frag_hash,
- mnesia_frag_old_hash,
mnesia_index,
mnesia_kernel_sup,
mnesia_late_loader,
@@ -311,12 +344,12 @@ ms() ->
%% Activity mgt
-spec abort(_) -> no_return().
-
abort(Reason = {aborted, _}) ->
exit(Reason);
abort(Reason) ->
exit({aborted, Reason}).
+-spec is_transaction() -> boolean().
is_transaction() ->
case get(mnesia_activity_state) of
{_, Tid, _Ts} when element(1,Tid) == tid ->
@@ -325,29 +358,52 @@ is_transaction() ->
false
end.
+-spec transaction(Fun) -> t_result(Res) when
+ Fun :: fun(() -> Res).
transaction(Fun) ->
transaction(get(mnesia_activity_state), Fun, [], infinity, ?DEFAULT_ACCESS, async).
+
+-spec transaction(Fun, Retries) -> t_result(Res) when
+ Fun :: fun(() -> Res),
+ Retries :: non_neg_integer() | 'infinity';
+ (Fun, [Arg::_]) -> t_result(Res) when
+ Fun :: fun((...) -> Res).
transaction(Fun, Retries) when is_integer(Retries), Retries >= 0 ->
transaction(get(mnesia_activity_state), Fun, [], Retries, ?DEFAULT_ACCESS, async);
transaction(Fun, Retries) when Retries == infinity ->
transaction(get(mnesia_activity_state), Fun, [], Retries, ?DEFAULT_ACCESS, async);
transaction(Fun, Args) ->
transaction(get(mnesia_activity_state), Fun, Args, infinity, ?DEFAULT_ACCESS, async).
+
+-spec transaction(Fun, [Arg::_], Retries) -> t_result(Res) when
+ Fun :: fun((...) -> Res),
+ Retries :: non_neg_integer() | 'infinity'.
transaction(Fun, Args, Retries) ->
transaction(get(mnesia_activity_state), Fun, Args, Retries, ?DEFAULT_ACCESS, async).
+-spec sync_transaction(Fun) -> t_result(Res) when
+ Fun :: fun(() -> Res).
sync_transaction(Fun) ->
transaction(get(mnesia_activity_state), Fun, [], infinity, ?DEFAULT_ACCESS, sync).
+
+-spec sync_transaction(Fun, Retries) -> t_result(Res) when
+ Fun :: fun(() -> Res),
+ Retries :: non_neg_integer() | 'infinity';
+ (Fun, [Arg::_]) -> t_result(Res) when
+ Fun :: fun((...) -> Res).
sync_transaction(Fun, Retries) when is_integer(Retries), Retries >= 0 ->
transaction(get(mnesia_activity_state), Fun, [], Retries, ?DEFAULT_ACCESS, sync);
sync_transaction(Fun, Retries) when Retries == infinity ->
transaction(get(mnesia_activity_state), Fun, [], Retries, ?DEFAULT_ACCESS, sync);
sync_transaction(Fun, Args) ->
transaction(get(mnesia_activity_state), Fun, Args, infinity, ?DEFAULT_ACCESS, sync).
+
+-spec sync_transaction(Fun, [Arg::_], Retries) -> t_result(Res) when
+ Fun :: fun((...) -> Res),
+ Retries :: non_neg_integer() | 'infinity'.
sync_transaction(Fun, Args, Retries) ->
transaction(get(mnesia_activity_state), Fun, Args, Retries, ?DEFAULT_ACCESS, sync).
-
transaction(State, Fun, Args, Retries, Mod, Kind)
when is_function(Fun), is_list(Args), Retries == infinity, is_atom(Mod) ->
mnesia_tm:transaction(State, Fun, Args, Retries, Mod, Kind);
@@ -363,28 +419,60 @@ non_transaction(State, Fun, Args, ActivityKind, Mod)
non_transaction(_State, Fun, Args, _ActivityKind, _Mod) ->
{aborted, {badarg, Fun, Args}}.
+-spec async_dirty(Fun) -> Res | no_return() when
+ Fun :: fun(() -> Res).
async_dirty(Fun) ->
async_dirty(Fun, []).
+
+-spec async_dirty(Fun, [Arg::_]) -> Res | no_return() when
+ Fun :: fun((...) -> Res).
async_dirty(Fun, Args) ->
non_transaction(get(mnesia_activity_state), Fun, Args, async_dirty, ?DEFAULT_ACCESS).
+-spec sync_dirty(Fun) -> Res | no_return() when
+ Fun :: fun(() -> Res).
sync_dirty(Fun) ->
sync_dirty(Fun, []).
+
+-spec sync_dirty(Fun, [Arg::_]) -> Res | no_return() when
+ Fun :: fun((...) -> Res).
sync_dirty(Fun, Args) ->
non_transaction(get(mnesia_activity_state), Fun, Args, sync_dirty, ?DEFAULT_ACCESS).
+-spec ets(Fun) -> Res | no_return() when
+ Fun :: fun(() -> Res).
ets(Fun) ->
ets(Fun, []).
+
+-spec ets(Fun, [Arg::_]) -> Res | no_return() when
+ Fun :: fun((...) -> Res).
ets(Fun, Args) ->
non_transaction(get(mnesia_activity_state), Fun, Args, ets, ?DEFAULT_ACCESS).
+-spec activity(Kind, Fun) -> t_result(Res) | Res when
+ Kind :: activity(),
+ Fun :: fun(() -> Res).
activity(Kind, Fun) ->
activity(Kind, Fun, []).
+
+-spec activity(Kind, Fun, [Arg::_]) -> t_result(Res) | Res when
+ Kind :: activity(),
+ Fun :: fun((...) -> Res);
+ (Kind, Fun, Mod) -> t_result(Res) | Res when
+ Kind :: activity(),
+ Fun :: fun(() -> Res),
+ Mod :: atom().
+
activity(Kind, Fun, Args) when is_list(Args) ->
activity(Kind, Fun, Args, mnesia_monitor:get_env(access_module));
activity(Kind, Fun, Mod) ->
activity(Kind, Fun, [], Mod).
+-spec activity(Kind, Fun, [Arg::_], Mod) -> t_result(Res) | Res when
+ Kind :: activity(),
+ Fun :: fun((...) -> Res),
+ Mod :: atom().
+
activity(Kind, Fun, Args, Mod) ->
State = get(mnesia_activity_state),
case Kind of
@@ -414,7 +502,11 @@ wrap_trans(State, Fun, Args, Retries, Mod, Kind) ->
%% Nodes may either be a list of nodes or one node as an atom
%% Mnesia on all Nodes must be connected to each other, but
%% it is not neccessary that they are up and running.
-
+-spec lock(LockItem, LockKind) -> list() | tuple() | no_return() when
+ LockItem :: {'record', table(), Key::term()} |
+ {'table', table()} |
+ {'global', Key::term(), MnesiaNodes::[node()]},
+ LockKind :: lock_kind() | 'load'.
lock(LockItem, LockKind) ->
case get(mnesia_activity_state) of
{?DEFAULT_ACCESS, Tid, Ts} ->
@@ -425,6 +517,9 @@ lock(LockItem, LockKind) ->
abort(no_transaction)
end.
+-spec lock_table(Tab::table(), LockKind) -> [MnesiaNode] | no_return() when
+ MnesiaNode :: node(),
+ LockKind :: lock_kind() | load.
lock_table(Tab, LockKind) ->
lock({table, Tab}, LockKind).
@@ -446,11 +541,13 @@ lock(Tid, Ts, LockItem, LockKind) ->
end.
%% Grab a read lock on a whole table
+-spec read_lock_table(Tab::table()) -> ok.
read_lock_table(Tab) ->
lock({table, Tab}, read),
ok.
%% Grab a write lock on a whole table
+-spec write_lock_table(Tab::table()) -> ok.
write_lock_table(Tab) ->
lock({table, Tab}, write),
ok.
@@ -515,17 +612,19 @@ good_global_nodes(Nodes) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Access within an activity - updates
-
+-spec write(Record::tuple()) -> 'ok'.
write(Val) when is_tuple(Val), tuple_size(Val) > 2 ->
Tab = element(1, Val),
write(Tab, Val, write);
write(Val) ->
abort({bad_type, Val}).
+-spec s_write(Record::tuple()) -> 'ok'.
s_write(Val) when is_tuple(Val), tuple_size(Val) > 2 ->
Tab = element(1, Val),
write(Tab, Val, sticky_write).
+-spec write(Tab::table(), Record::tuple(), LockKind::write_locks()) -> 'ok'.
write(Tab, Val, LockKind) ->
case get(mnesia_activity_state) of
{?DEFAULT_ACCESS, Tid, Ts} ->
@@ -572,16 +671,19 @@ write_to_store(Tab, Store, Oid, Val) ->
end,
ok.
+-spec delete({Tab::table(), Key::_}) -> 'ok'.
delete({Tab, Key}) ->
delete(Tab, Key, write);
delete(Oid) ->
abort({bad_type, Oid}).
+-spec s_delete({Tab::table(), Key::_}) -> 'ok'.
s_delete({Tab, Key}) ->
delete(Tab, Key, sticky_write);
s_delete(Oid) ->
abort({bad_type, Oid}).
+-spec delete(Tab::table(), Key::_, LockKind::write_locks()) -> 'ok'.
delete(Tab, Key, LockKind) ->
case get(mnesia_activity_state) of
{?DEFAULT_ACCESS, Tid, Ts} ->
@@ -618,18 +720,21 @@ delete(Tid, Ts, Tab, Key, LockKind)
delete(_Tid, _Ts, Tab, _Key, _LockKind) ->
abort({bad_type, Tab}).
+-spec delete_object(Rec::tuple()) -> 'ok'.
delete_object(Val) when is_tuple(Val), tuple_size(Val) > 2 ->
Tab = element(1, Val),
delete_object(Tab, Val, write);
delete_object(Val) ->
abort({bad_type, Val}).
+-spec s_delete_object(Rec::tuple()) -> 'ok'.
s_delete_object(Val) when is_tuple(Val), tuple_size(Val) > 2 ->
Tab = element(1, Val),
delete_object(Tab, Val, sticky_write);
s_delete_object(Val) ->
abort({bad_type, Val}).
+-spec delete_object(Tab::table(), Rec::tuple(), LockKind::write_locks()) -> 'ok'.
delete_object(Tab, Val, LockKind) ->
case get(mnesia_activity_state) of
{?DEFAULT_ACCESS, Tid, Ts} ->
@@ -689,19 +794,23 @@ do_delete_object(Tid, Ts, Tab, Val, LockKind) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Access within an activity - read
+-spec read(Tab::table(), Key::_) -> [tuple()].
read(Tab, Key) ->
read(Tab, Key, read).
+-spec read({Tab::table(), Key::_}) -> [tuple()].
read({Tab, Key}) ->
read(Tab, Key, read);
read(Oid) ->
abort({bad_type, Oid}).
+-spec wread({Tab::table(), Key::_}) -> [tuple()].
wread({Tab, Key}) ->
read(Tab, Key, write);
wread(Oid) ->
abort({bad_type, Oid}).
+-spec read(Tab::table(), Key::_, LockKind::lock_kind()) -> [tuple()].
read(Tab, Key, LockKind) ->
case get(mnesia_activity_state) of
{?DEFAULT_ACCESS, Tid, Ts} ->
@@ -738,6 +847,7 @@ read(Tid, Ts, Tab, Key, LockKind)
read(_Tid, _Ts, Tab, _Key, _LockKind) ->
abort({bad_type, Tab}).
+-spec first(Tab::table()) -> Key::term().
first(Tab) ->
case get(mnesia_activity_state) of
{?DEFAULT_ACCESS, Tid, Ts} ->
@@ -765,6 +875,7 @@ first(Tid, Ts, Tab)
first(_Tid, _Ts,Tab) ->
abort({bad_type, Tab}).
+-spec last(Tab::table()) -> Key::term().
last(Tab) ->
case get(mnesia_activity_state) of
{?DEFAULT_ACCESS, Tid, Ts} ->
@@ -792,6 +903,7 @@ last(Tid, Ts, Tab)
last(_Tid, _Ts,Tab) ->
abort({bad_type, Tab}).
+-spec next(Tab::table(), Key::term()) -> NextKey::term().
next(Tab,Key) ->
case get(mnesia_activity_state) of
{?DEFAULT_ACCESS,Tid,Ts} ->
@@ -818,6 +930,7 @@ next(Tid,Ts,Tab,Key)
next(_Tid, _Ts,Tab,_) ->
abort({bad_type, Tab}).
+-spec prev(Tab::table(), Key::term()) -> PrevKey::term().
prev(Tab,Key) ->
case get(mnesia_activity_state) of
{?DEFAULT_ACCESS,Tid,Ts} ->
@@ -952,6 +1065,8 @@ ts_keys_1([], Acc) ->
%%%%%%%%%%%%%%%%%%%%%
%% Iterators
+-spec foldl(Fun, Acc0, Tab::table()) -> Acc when
+ Fun::fun((Record::tuple(), Acc0) -> Acc).
foldl(Fun, Acc, Tab) ->
foldl(Fun, Acc, Tab, read).
@@ -992,6 +1107,8 @@ do_foldl(A, O, Tab, Key, Fun, Acc, Type, Stored) -> %% Type is set or bag
{_, Tid, Ts} = get(mnesia_activity_state),
do_foldl(Tid, Ts, Tab, dirty_next(Tab, Key), Fun, NewAcc, Type, NewStored).
+-spec foldr(Fun, Acc0, Tab::table()) -> Acc when
+ Fun::fun((Record::tuple(), Acc0) -> Acc).
foldr(Fun, Acc, Tab) ->
foldr(Fun, Acc, Tab, read).
foldr(Fun, Acc, Tab, LockKind) when is_function(Fun) ->
@@ -1105,12 +1222,15 @@ add_written_to_bag([{_, _ , delete} | Tail], _Objs, _Ack) ->
add_written_to_bag([{_, Val, delete_object} | Tail], Objs, Ack) ->
add_written_to_bag(Tail, lists:delete(Val, Objs), lists:delete(Val, Ack)).
+-spec match_object(Pattern::tuple()) -> [Record::tuple()].
match_object(Pat) when is_tuple(Pat), tuple_size(Pat) > 2 ->
Tab = element(1, Pat),
match_object(Tab, Pat, read);
match_object(Pat) ->
abort({bad_type, Pat}).
+-spec match_object(Tab,Pattern,LockKind) -> [Record] when
+ Tab::table(),Pattern::tuple(),LockKind::lock_kind(),Record::tuple().
match_object(Tab, Pat, LockKind) ->
case get(mnesia_activity_state) of
{?DEFAULT_ACCESS, Tid, Ts} ->
@@ -1270,9 +1390,13 @@ deloid(Oid, [H | T]) ->
%%%%%%%%%%%%%%%%%%
% select
-
+-spec select(Tab, Spec) -> [Match] when
+ Tab::table(), Spec::ets:match_spec(), Match::term().
select(Tab, Pat) ->
select(Tab, Pat, read).
+-spec select(Tab, Spec, LockKind) -> [Match] when
+ Tab::table(), Spec::ets:match_spec(),
+ Match::term(),LockKind::lock_kind().
select(Tab, Pat, LockKind)
when is_atom(Tab), Tab /= schema, is_list(Pat) ->
case get(mnesia_activity_state) of
@@ -1331,6 +1455,11 @@ select_lock(Tid,Ts,LockKind,Spec,Tab) ->
end.
%% Breakable Select
+-spec select(Tab, Spec, N, LockKind) -> {[Match], Cont} | '$end_of_table' when
+ Tab::table(), Spec::ets:match_spec(),
+ Match::term(), N::non_neg_integer(),
+ LockKind::lock_kind(),
+ Cont::select_continuation().
select(Tab, Pat, NObjects, LockKind)
when is_atom(Tab), Tab /= schema, is_list(Pat), is_integer(NObjects) ->
case get(mnesia_activity_state) of
@@ -1387,6 +1516,9 @@ fun_select(Tid, Ts, Tab, Spec, LockKind, TabPat, Init, NObjects, Node, Storage)
select_state(Init(Spec),Def)
end.
+-spec select(Cont) -> {[Match], Cont} | '$end_of_table' when
+ Match::term(),
+ Cont::select_continuation().
select(Cont) ->
case get(mnesia_activity_state) of
{?DEFAULT_ACCESS, Tid, Ts} ->
@@ -1436,6 +1568,7 @@ get_record_pattern([]) -> [];
get_record_pattern([{M,C,_B}|R]) ->
[{M,C,['$_']} | get_record_pattern(R)].
+-spec all_keys(Tab::table()) -> [Key::term()].
all_keys(Tab) ->
case get(mnesia_activity_state) of
{?DEFAULT_ACCESS, Tid, Ts} ->
@@ -1460,12 +1593,20 @@ all_keys(Tid, Ts, Tab, LockKind)
all_keys(_Tid, _Ts, Tab, _LockKind) ->
abort({bad_type, Tab}).
+-spec index_match_object(Pattern, Attr) -> [Record] when
+ Pattern::tuple(), Attr::index_attr(), Record::tuple().
index_match_object(Pat, Attr) when is_tuple(Pat), tuple_size(Pat) > 2 ->
Tab = element(1, Pat),
index_match_object(Tab, Pat, Attr, read);
index_match_object(Pat, _Attr) ->
abort({bad_type, Pat}).
+-spec index_match_object(Tab, Pattern, Attr, LockKind) -> [Record] when
+ Tab::table(),
+ Pattern::tuple(),
+ Attr::index_attr(),
+ LockKind::lock_kind(),
+ Record::tuple().
index_match_object(Tab, Pat, Attr, LockKind) ->
case get(mnesia_activity_state) of
{?DEFAULT_ACCESS, Tid, Ts} ->
@@ -1502,6 +1643,11 @@ index_match_object(Tid, Ts, Tab, Pat, Attr, LockKind)
index_match_object(_Tid, _Ts, Tab, Pat, _Attr, _LockKind) ->
abort({bad_type, Tab, Pat}).
+-spec index_read(Tab, Key, Attr) -> [Record] when
+ Tab::table(),
+ Key::term(),
+ Attr::index_attr(),
+ Record::tuple().
index_read(Tab, Key, Attr) ->
case get(mnesia_activity_state) of
{?DEFAULT_ACCESS, Tid, Ts} ->
@@ -1541,13 +1687,14 @@ index_read(_Tid, _Ts, Tab, _Key, _Attr, _LockKind) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Dirty access regardless of activities - updates
-
+-spec dirty_write(Record::tuple()) -> 'ok'.
dirty_write(Val) when is_tuple(Val), tuple_size(Val) > 2 ->
Tab = element(1, Val),
dirty_write(Tab, Val);
dirty_write(Val) ->
abort({bad_type, Val}).
+-spec dirty_write(Tab::table(), Record::tuple()) -> 'ok'.
dirty_write(Tab, Val) ->
do_dirty_write(async_dirty, Tab, Val).
@@ -1559,11 +1706,13 @@ do_dirty_write(SyncMode, Tab, Val)
do_dirty_write(_SyncMode, Tab, Val) ->
abort({bad_type, Tab, Val}).
+-spec dirty_delete({Tab::table(), Key::_}) -> 'ok'.
dirty_delete({Tab, Key}) ->
dirty_delete(Tab, Key);
dirty_delete(Oid) ->
abort({bad_type, Oid}).
+-spec dirty_delete(Tab::table(), Key::_) -> 'ok'.
dirty_delete(Tab, Key) ->
do_dirty_delete(async_dirty, Tab, Key).
@@ -1573,12 +1722,14 @@ do_dirty_delete(SyncMode, Tab, Key) when is_atom(Tab), Tab /= schema ->
do_dirty_delete(_SyncMode, Tab, _Key) ->
abort({bad_type, Tab}).
+-spec dirty_delete_object(Record::tuple()) -> 'ok'.
dirty_delete_object(Val) when is_tuple(Val), tuple_size(Val) > 2 ->
Tab = element(1, Val),
dirty_delete_object(Tab, Val);
dirty_delete_object(Val) ->
abort({bad_type, Val}).
+-spec dirty_delete_object(Tab::table(), Record::tuple()) -> 'ok'.
dirty_delete_object(Tab, Val) ->
do_dirty_delete_object(async_dirty, Tab, Val).
@@ -1596,12 +1747,15 @@ do_dirty_delete_object(_SyncMode, Tab, Val) ->
abort({bad_type, Tab, Val}).
%% A Counter is an Oid being {CounterTab, CounterName}
-
+-spec dirty_update_counter({Tab::table(), Key::_}, Incr::integer()) ->
+ NewVal::integer().
dirty_update_counter({Tab, Key}, Incr) ->
dirty_update_counter(Tab, Key, Incr);
dirty_update_counter(Counter, _Incr) ->
abort({bad_type, Counter}).
+-spec dirty_update_counter(Tab::table(), Key::_, Incr::integer()) ->
+ NewVal::integer().
dirty_update_counter(Tab, Key, Incr) ->
do_dirty_update_counter(async_dirty, Tab, Key, Incr).
@@ -1620,23 +1774,28 @@ do_dirty_update_counter(_SyncMode, Tab, _Key, Incr) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Dirty access regardless of activities - read
+-spec dirty_read({Tab::table(), Key::_}) -> [tuple()].
dirty_read({Tab, Key}) ->
dirty_read(Tab, Key);
dirty_read(Oid) ->
abort({bad_type, Oid}).
+-spec dirty_read(Tab::table(), Key::_) -> [tuple()].
dirty_read(Tab, Key)
when is_atom(Tab), Tab /= schema ->
dirty_rpc(Tab, mnesia_lib, db_get, [Tab, Key]);
dirty_read(Tab, _Key) ->
abort({bad_type, Tab}).
+-spec dirty_match_object(Pattern::tuple()) -> [Record::tuple()].
dirty_match_object(Pat) when is_tuple(Pat), tuple_size(Pat) > 2 ->
Tab = element(1, Pat),
dirty_match_object(Tab, Pat);
dirty_match_object(Pat) ->
abort({bad_type, Pat}).
+-spec dirty_match_object(Tab,Pattern) -> [Record] when
+ Tab::table(), Pattern::tuple(), Record::tuple().
dirty_match_object(Tab, Pat)
when is_atom(Tab), Tab /= schema, is_tuple(Pat), tuple_size(Pat) > 2 ->
dirty_rpc(Tab, ?MODULE, remote_dirty_match_object, [Tab, Pat]);
@@ -1666,6 +1825,8 @@ remote_dirty_match_object(Tab, Pat, []) ->
remote_dirty_match_object(Tab, Pat, _PosList) ->
abort({bad_type, Tab, Pat}).
+-spec dirty_select(Tab, Spec) -> [Match] when
+ Tab::table(), Spec::ets:match_spec(), Match::term().
dirty_select(Tab, Spec) when is_atom(Tab), Tab /= schema, is_list(Spec) ->
dirty_rpc(Tab, ?MODULE, remote_dirty_select, [Tab, Spec]);
dirty_select(Tab, Spec) ->
@@ -1714,6 +1875,7 @@ dirty_sel_cont(#mnesia_select{cont='$end_of_table'}) -> '$end_of_table';
dirty_sel_cont(#mnesia_select{node=Node,tab=Tab,storage=Type,cont=Cont,orig=Ms}) ->
do_dirty_rpc(Tab,Node,mnesia_lib,db_select_cont,[Type,Cont,Ms]).
+-spec dirty_all_keys(Tab::table()) -> [Key::term()].
dirty_all_keys(Tab) when is_atom(Tab), Tab /= schema ->
case ?catch_val({Tab, wild_pattern}) of
{'EXIT', _} ->
@@ -1729,12 +1891,19 @@ dirty_all_keys(Tab) when is_atom(Tab), Tab /= schema ->
dirty_all_keys(Tab) ->
abort({bad_type, Tab}).
+-spec dirty_index_match_object(Pattern, Attr) -> [Record] when
+ Pattern::tuple(), Attr::index_attr(), Record::tuple().
dirty_index_match_object(Pat, Attr) when is_tuple(Pat), tuple_size(Pat) > 2 ->
Tab = element(1, Pat),
dirty_index_match_object(Tab, Pat, Attr);
dirty_index_match_object(Pat, _Attr) ->
abort({bad_type, Pat}).
+-spec dirty_index_match_object(Tab, Pattern, Attr) -> [Record] when
+ Tab::table(),
+ Pattern::tuple(),
+ Attr::index_attr(),
+ Record::tuple().
dirty_index_match_object(Tab, Pat, Attr)
when is_atom(Tab), Tab /= schema, is_tuple(Pat), tuple_size(Pat) > 2 ->
case mnesia_schema:attr_tab_to_pos(Tab, Attr) of
@@ -1758,6 +1927,11 @@ dirty_index_match_object(Tab, Pat, Attr)
dirty_index_match_object(Tab, Pat, _Attr) ->
abort({bad_type, Tab, Pat}).
+-spec dirty_index_read(Tab, Key, Attr) -> [Record] when
+ Tab::table(),
+ Key::term(),
+ Attr::index_attr(),
+ Record::tuple().
dirty_index_read(Tab, Key, Attr) when is_atom(Tab), Tab /= schema ->
Pos = mnesia_schema:attr_tab_to_pos(Tab, Attr),
case has_var(Key) of
@@ -1769,26 +1943,31 @@ dirty_index_read(Tab, Key, Attr) when is_atom(Tab), Tab /= schema ->
dirty_index_read(Tab, _Key, _Attr) ->
abort({bad_type, Tab}).
+%% do not use only for backwards compatibility
dirty_slot(Tab, Slot) when is_atom(Tab), Tab /= schema, is_integer(Slot) ->
dirty_rpc(Tab, mnesia_lib, db_slot, [Tab, Slot]);
dirty_slot(Tab, Slot) ->
abort({bad_type, Tab, Slot}).
+-spec dirty_first(Tab::table()) -> Key::term().
dirty_first(Tab) when is_atom(Tab), Tab /= schema ->
dirty_rpc(Tab, mnesia_lib, db_first, [Tab]);
dirty_first(Tab) ->
abort({bad_type, Tab}).
+-spec dirty_last(Tab::table()) -> Key::term().
dirty_last(Tab) when is_atom(Tab), Tab /= schema ->
dirty_rpc(Tab, mnesia_lib, db_last, [Tab]);
dirty_last(Tab) ->
abort({bad_type, Tab}).
+-spec dirty_next(Tab::table(), Key::_) -> NextKey::term().
dirty_next(Tab, Key) when is_atom(Tab), Tab /= schema ->
dirty_rpc(Tab, mnesia_lib, db_next_key, [Tab, Key]);
dirty_next(Tab, _Key) ->
abort({bad_type, Tab}).
+-spec dirty_prev(Tab::table(), Key::_) -> PrevKey::term().
dirty_prev(Tab, Key) when is_atom(Tab), Tab /= schema ->
dirty_rpc(Tab, mnesia_lib, db_prev_key, [Tab, Key]);
dirty_prev(Tab, _Key) ->
@@ -1839,7 +2018,7 @@ do_dirty_rpc(Tab, Node, M, F, Args) ->
%% Info
%% Info about one table
--spec table_info(atom(), any()) -> any().
+-spec table_info(Tab::table(), Item::term()) -> Info::term().
table_info(Tab, Item) ->
case get(mnesia_activity_state) of
undefined ->
@@ -1928,16 +2107,20 @@ bad_info_reply(_Tab, memory) -> 0;
bad_info_reply(Tab, Item) -> abort({no_exists, Tab, Item}).
%% Raw info about all tables
+-spec schema() -> ok.
schema() ->
mnesia_schema:info().
%% Raw info about one tables
+-spec schema(Tab::table()) -> ok.
schema(Tab) ->
mnesia_schema:info(Tab).
+-spec error_description(Error::term()) -> string().
error_description(Err) ->
mnesia_lib:error_desc(Err).
+-spec info() -> ok.
info() ->
case mnesia_lib:is_running() of
yes ->
@@ -2063,6 +2246,7 @@ display_tab_info() ->
Rdisp = fun({Rpat, Rtabs}) -> io:format("~p = ~p~n", [Rpat, Rtabs]) end,
lists:foreach(Rdisp, lists:sort(Repl)).
+-spec get_backend_types() -> [BackendType::term()].
get_backend_types() ->
case ?catch_val({schema, user_property, mnesia_backend_types}) of
{'EXIT', _} ->
@@ -2071,6 +2255,7 @@ get_backend_types() ->
lists:sort(Ts)
end.
+-spec get_index_plugins() -> [IndexPlugins::term()].
get_index_plugins() ->
case ?catch_val({schema, user_property, mnesia_index_plugins}) of
{'EXIT', _} ->
@@ -2119,6 +2304,7 @@ storage_count(T, {U, R, D, DO, Ext}) ->
{ext, A, _} -> {U, R, D, DO, orddict:append(A, T, Ext)}
end.
+-spec system_info(Iterm::term()) -> Info::term().
system_info(Item) ->
try system_info2(Item)
catch _:Error -> abort(Error)
@@ -2368,83 +2554,134 @@ load_mnesia_or_abort() ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Database mgt
+-spec create_schema(Ns::[node()]) -> 'ok' | {'error', Reason::term()}.
create_schema(Ns) ->
create_schema(Ns, []).
+-spec create_schema(Ns::[node()], [Prop]) -> 'ok' | {'error', Reason::term()} when
+ Prop :: BackendType | IndexPlugin,
+ BackendType :: {backend_types, [{Name::atom(), Module::module()}]},
+ IndexPlugin :: {index_plugins, [{{Name::atom()}, Module::module(), Function::atom()}]}.
create_schema(Ns, Properties) ->
mnesia_bup:create_schema(Ns, Properties).
+-spec delete_schema(Ns::[node()]) -> 'ok' | {'error', Reason::term()}.
delete_schema(Ns) ->
mnesia_schema:delete_schema(Ns).
+-spec add_backend_type(Name::atom(), Module::module()) -> t_result('ok').
add_backend_type(Alias, Module) ->
mnesia_schema:add_backend_type(Alias, Module).
+-spec backup(Dest::term()) -> 'ok' | {'error', Reason::term()}.
backup(Opaque) ->
mnesia_log:backup(Opaque).
+-spec backup(Dest::term(), Mod::module()) ->
+ 'ok' | {'error', Reason::term()}.
backup(Opaque, Mod) ->
mnesia_log:backup(Opaque, Mod).
+-spec traverse_backup(Src::term(), Dest::term(), Fun, Acc) ->
+ {'ok', Acc} | {'error', Reason::term()} when
+ Fun :: fun((Items, Acc) -> {Items,Acc}).
traverse_backup(S, T, Fun, Acc) ->
mnesia_bup:traverse_backup(S, T, Fun, Acc).
+-spec traverse_backup(Src::term(), SrcMod::module(),
+ Dest::term(), DestMod::module(),
+ Fun, Acc) ->
+ {'ok', Acc} | {'error', Reason::term()} when
+ Fun :: fun((Items, Acc) -> {Items,Acc}).
traverse_backup(S, SM, T, TM, F, A) ->
mnesia_bup:traverse_backup(S, SM, T, TM, F, A).
+-spec install_fallback(Src::term()) -> 'ok' | {'error', Reason::term()}.
install_fallback(Opaque) ->
mnesia_bup:install_fallback(Opaque).
+-spec install_fallback(Src::term(), Mod::module()|[Opt]) ->
+ 'ok' | {'error', Reason::term()} when
+ Opt :: Module | Scope | Dir,
+ Module :: {'module', Mod::module()},
+ Scope :: {'scope', 'global' | 'local'},
+ Dir :: {'mnesia_dir', Dir::string()}.
install_fallback(Opaque, Mod) ->
mnesia_bup:install_fallback(Opaque, Mod).
+-spec uninstall_fallback() -> 'ok' | {'error', Reason::term()}.
uninstall_fallback() ->
mnesia_bup:uninstall_fallback().
+-spec uninstall_fallback(Args) -> 'ok' | {'error', Reason::term()} when
+ Args :: [{'mnesia_dir', Dir::string()}].
uninstall_fallback(Args) ->
mnesia_bup:uninstall_fallback(Args).
+-spec activate_checkpoint([Arg]) -> {'ok', Name, [node()]} | {'error', Reason::term()} when
+ Arg :: {'name', Name} | {'max', [table()]} | {'min', [table()]} |
+ {'allow_remote', boolean()} | {'ram_overrides_dump', boolean()}.
activate_checkpoint(Args) ->
mnesia_checkpoint:activate(Args).
+-spec deactivate_checkpoint(Name::_) -> 'ok' | {'error', Reason::term()}.
deactivate_checkpoint(Name) ->
mnesia_checkpoint:deactivate(Name).
+-spec backup_checkpoint(Name::_, Dest::_) -> 'ok' | {'error', Reason::term()}.
backup_checkpoint(Name, Opaque) ->
mnesia_log:backup_checkpoint(Name, Opaque).
+-spec backup_checkpoint(Name::_, Dest::_, Mod::module()) ->
+ 'ok' | {'error', Reason::term()}.
backup_checkpoint(Name, Opaque, Mod) ->
mnesia_log:backup_checkpoint(Name, Opaque, Mod).
+-spec restore(Src::_, [Arg]) -> t_result([table()]) when
+ Op :: 'skip_tables' | 'clear_tables' | 'keep_tables' | 'restore_tables',
+ Arg :: {'module', module()} | {Op, [table()]} | {'default_op', Op}.
restore(Opaque, Args) ->
mnesia_schema:restore(Opaque, Args).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Table mgt
-
+-spec create_table([Arg]) -> t_result('ok') when
+ Arg :: {'name', table()} | create_option().
create_table(Arg) ->
mnesia_schema:create_table(Arg).
+
+-spec create_table(Name::table(), [create_option()]) -> t_result('ok').
create_table(Name, Arg) when is_list(Arg) ->
mnesia_schema:create_table([{name, Name}| Arg]);
create_table(Name, Arg) ->
{aborted, badarg, Name, Arg}.
+-spec delete_table(Tab::table()) -> t_result('ok').
delete_table(Tab) ->
mnesia_schema:delete_table(Tab).
+-spec add_table_copy(Tab::table(), N::node(), ST::storage_type()) -> t_result(ok).
add_table_copy(Tab, N, S) ->
mnesia_schema:add_table_copy(Tab, N, S).
+
+-spec del_table_copy(Tab::table(), N::node()) -> t_result(ok).
del_table_copy(Tab, N) ->
mnesia_schema:del_table_copy(Tab, N).
+-spec move_table_copy(Tab::table(), From::node(), To::node()) -> t_result(ok).
move_table_copy(Tab, From, To) ->
mnesia_schema:move_table(Tab, From, To).
+-spec add_table_index(Tab::table(), I::index_attr()) -> t_result(ok).
add_table_index(Tab, Ix) ->
mnesia_schema:add_table_index(Tab, Ix).
+-spec del_table_index(Tab::table(), I::index_attr()) -> t_result(ok).
del_table_index(Tab, Ix) ->
mnesia_schema:del_table_index(Tab, Ix).
+-spec transform_table(Tab::table(), Fun, [Attr]) -> t_result(ok) when
+ Attr :: atom(),
+ Fun:: fun((Record::tuple()) -> Transformed::tuple()).
transform_table(Tab, Fun, NewA) ->
try val({Tab, record_name}) of
OldRN -> mnesia_schema:transform_table(Tab, Fun, NewA, OldRN)
@@ -2452,12 +2689,18 @@ transform_table(Tab, Fun, NewA) ->
mnesia:abort(Reason)
end.
+-spec transform_table(Tab::table(), Fun, [Attr], RecName) -> t_result(ok) when
+ RecName :: atom(),
+ Attr :: atom(),
+ Fun:: fun((Record::tuple()) -> Transformed::tuple()).
transform_table(Tab, Fun, NewA, NewRN) ->
mnesia_schema:transform_table(Tab, Fun, NewA, NewRN).
+-spec change_table_copy_type(Tab::table(), Node::node(), To::storage_type()) -> t_result(ok).
change_table_copy_type(T, N, S) ->
mnesia_schema:change_table_copy_type(T, N, S).
+-spec clear_table(Tab::table()) -> t_result(ok).
clear_table(Tab) ->
case get(mnesia_activity_state) of
State = {Mod, Tid, _Ts} when element(1, Tid) =/= tid ->
@@ -2487,19 +2730,22 @@ clear_table(Tid, Ts, Tab, Obj) when element(1, Tid) =:= tid ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Table mgt - user properties
-
+-spec read_table_property(Tab::table(), PropKey::term()) -> Res::tuple().
read_table_property(Tab, PropKey) ->
val({Tab, user_property, PropKey}).
+-spec write_table_property(Tab::table(), Prop::tuple()) -> t_result(ok).
write_table_property(Tab, Prop) ->
mnesia_schema:write_table_property(Tab, Prop).
+-spec delete_table_property(Tab::table(), PropKey::term()) -> t_result(ok).
delete_table_property(Tab, PropKey) ->
mnesia_schema:delete_table_property(Tab, PropKey).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Table mgt - user properties
+-spec change_table_frag(Tab::table(), FP::term()) -> t_result(ok).
change_table_frag(Tab, FragProp) ->
mnesia_schema:change_table_frag(Tab, FragProp).
@@ -2507,28 +2753,38 @@ change_table_frag(Tab, FragProp) ->
%% Table mgt - table load
%% Dump a ram table to disc
+-spec dump_tables([Tab::table()]) -> t_result(ok).
dump_tables(Tabs) ->
mnesia_schema:dump_tables(Tabs).
%% allow the user to wait for some tables to be loaded
+-spec wait_for_tables([Tab::table()], TMO::timeout()) ->
+ 'ok' | {'timeout', [table()]} | {'error', Reason::term()}.
wait_for_tables(Tabs, Timeout) ->
mnesia_controller:wait_for_tables(Tabs, Timeout).
+-spec force_load_table(Tab::table()) -> 'yes' | {'error', Reason::term()}.
force_load_table(Tab) ->
case mnesia_controller:force_load_table(Tab) of
ok -> yes; % Backwards compatibility
Other -> Other
end.
+-spec change_table_access_mode(Tab::table(), Mode) -> t_result(ok) when
+ Mode :: 'read_only'|'read_write'.
change_table_access_mode(T, Access) ->
mnesia_schema:change_table_access_mode(T, Access).
+-spec change_table_load_order(Tab::table(), Order) -> t_result(ok) when
+ Order :: non_neg_integer().
change_table_load_order(T, O) ->
mnesia_schema:change_table_load_order(T, O).
+-spec change_table_majority(Tab::table(), M::boolean()) -> t_result(ok).
change_table_majority(T, M) ->
mnesia_schema:change_table_majority(T, M).
+-spec set_master_nodes(Ns::[node()]) -> 'ok' | {'error', Reason::term()}.
set_master_nodes(Nodes) when is_list(Nodes) ->
UseDir = system_info(use_dir),
IsRunning = system_info(is_running),
@@ -2567,6 +2823,8 @@ log_valid_master_nodes(Cstructs, Nodes, UseDir, IsRunning) ->
Args = lists:map(Fun, Cstructs),
mnesia_recover:log_master_nodes(Args, UseDir, IsRunning).
+-spec set_master_nodes(Tab::table(), Ns::[node()]) ->
+ 'ok' | {'error', Reason::term()}.
set_master_nodes(Tab, Nodes) when is_list(Nodes) ->
UseDir = system_info(use_dir),
IsRunning = system_info(is_running),
@@ -2617,31 +2875,39 @@ set_master_nodes(Tab, Nodes) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Misc admin
-
+-spec dump_log() -> 'dumped'.
dump_log() ->
mnesia_controller:sync_dump_log(user).
+-spec sync_log() -> 'ok' | {'error', Reason::term()}.
sync_log() ->
mnesia_monitor:sync_log(latest_log).
+-spec subscribe(What) -> {'ok', node()} | {'error', Reason::term()} when
+ What :: 'system' | 'activity' | {'table', table(), 'simple' | 'detailed'}.
subscribe(What) ->
mnesia_subscr:subscribe(self(), What).
+-spec unsubscribe(What) -> {'ok', node()} | {'error', Reason::term()} when
+ What :: 'system' | 'activity' | {'table', table(), 'simple' | 'detailed'}.
unsubscribe(What) ->
mnesia_subscr:unsubscribe(self(), What).
+-spec report_event(Event::_) -> 'ok'.
report_event(Event) ->
mnesia_lib:report_system_event({mnesia_user, Event}).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Snmp
-
+-spec snmp_open_table(Tab::table(), Snmp::snmp_struct()) -> ok.
snmp_open_table(Tab, Us) ->
mnesia_schema:add_snmp(Tab, Us).
+-spec snmp_close_table(Tab::table()) -> ok.
snmp_close_table(Tab) ->
mnesia_schema:del_snmp(Tab).
+-spec snmp_get_row(Tab::table(), [integer()]) -> {'ok', Row::tuple()} | 'undefined'.
snmp_get_row(Tab, RowIndex) when is_atom(Tab), Tab /= schema, is_list(RowIndex) ->
case get(mnesia_activity_state) of
{Mod, Tid, Ts=#tidstore{store=Store}} when element(1, Tid) =:= tid ->
@@ -2677,7 +2943,7 @@ snmp_get_row(Tab, _RowIndex) ->
abort({bad_type, Tab}).
%%%%%%%%%%%%%
-
+-spec snmp_get_next_index(Tab::table(), [integer()]) -> {'ok', [integer()]} | 'endOfTable'.
snmp_get_next_index(Tab, RowIndex) when is_atom(Tab), Tab /= schema, is_list(RowIndex) ->
{Next,OrigKey} = dirty_rpc(Tab, mnesia_snmp_hook, get_next_index, [Tab, RowIndex]),
case get(mnesia_activity_state) of
@@ -2719,7 +2985,7 @@ get_ordered_snmp_key(_, []) ->
endOfTable.
%%%%%%%%%%
-
+-spec snmp_get_mnesia_key(Tab::table(), [integer()]) -> {'ok', Key::term()} | 'undefined'.
snmp_get_mnesia_key(Tab, RowIndex) when is_atom(Tab), Tab /= schema, is_list(RowIndex) ->
case get(mnesia_activity_state) of
{_Mod, Tid, Ts} when element(1, Tid) =:= tid ->
@@ -2783,17 +3049,27 @@ snmp_filter_key(undefined, RowIndex, Tab, Store) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Textfile access
-
+-spec load_textfile(File::file:filename()) -> t_result(ok) | {'error', term()}.
load_textfile(F) ->
mnesia_text:load_textfile(F).
+
+-spec dump_to_textfile(File :: file:filename()) -> 'ok' | 'error' | {'error', term()}.
dump_to_textfile(F) ->
mnesia_text:dump_to_textfile(F).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% QLC Handles
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-spec table(Tab::table()) -> qlc:query_handle().
table(Tab) ->
table(Tab, []).
+
+-spec table(Tab::table(), Options) -> qlc:query_handle() when
+ Options :: Option | [Option],
+ Option :: MnesiaOpt | QlcOption,
+ MnesiaOpt :: {'traverse', SelectOp} | {lock, lock_kind()} | {n_objects, non_neg_integer()},
+ SelectOp :: 'select' | {'select', ets:match_spec()},
+ QlcOption :: {'key_equality', '==' | '=:='}.
table(Tab,Opts) ->
{[Trav,Lock,NObjects],QlcOptions0} =
qlc_opts(Opts,[{traverse,select},{lock,read},{n_objects,100}]),
diff --git a/lib/mnesia/src/mnesia.hrl b/lib/mnesia/src/mnesia.hrl
index 0716dd87c8..da7e662288 100644
--- a/lib/mnesia/src/mnesia.hrl
+++ b/lib/mnesia/src/mnesia.hrl
@@ -49,12 +49,12 @@
%% It's important that counter is first, since we compare tid's
--record(tid,
+-record(tid,
{counter, %% serial no for tid
pid}). %% owner of tid
--record(tidstore,
+-record(tidstore,
{store, %% current ets table for tid
up_stores = [], %% list of upper layer stores for nested trans
level = 1}). %% transaction level
@@ -128,5 +128,4 @@
mnesia_lib:eval_debug_fun(I, C, ?FILE, ?LINE)).
-else.
-define(eval_debug_fun(I, C), ok).
--endif.
-
+-endif.
diff --git a/lib/mnesia/src/mnesia_app.erl b/lib/mnesia/src/mnesia_app.erl
new file mode 100644
index 0000000000..4d89011db2
--- /dev/null
+++ b/lib/mnesia/src/mnesia_app.erl
@@ -0,0 +1,41 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 1996-2016. All Rights Reserved.
+%%
+%% Licensed under the Apache License, Version 2.0 (the "License");
+%% you may not use this file except in compliance with the License.
+%% You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing, software
+%% distributed under the License is distributed on an "AS IS" BASIS,
+%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+%% See the License for the specific language governing permissions and
+%% limitations under the License.
+%%
+%% %CopyrightEnd%
+%%
+
+-module(mnesia_app).
+
+-behaviour(application).
+
+-export([start/2, stop/1]).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% application callback functions
+
+start(normal, Args) ->
+ case mnesia_sup:start_link(Args) of
+ {ok, Pid} ->
+ {ok, Pid, {normal, Args}};
+ Error ->
+ Error
+ end;
+start(_, _) ->
+ {error, badarg}.
+
+stop(_StartArgs) ->
+ ok.
diff --git a/lib/mnesia/src/mnesia_checkpoint.erl b/lib/mnesia/src/mnesia_checkpoint.erl
index fc626940b4..8659e4622c 100644
--- a/lib/mnesia/src/mnesia_checkpoint.erl
+++ b/lib/mnesia/src/mnesia_checkpoint.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1996-2016
+%% Copyright Ericsson AB 1996-2017
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
diff --git a/lib/mnesia/src/mnesia_controller.erl b/lib/mnesia/src/mnesia_controller.erl
index 17b47c059e..6b93935cb4 100644
--- a/lib/mnesia/src/mnesia_controller.erl
+++ b/lib/mnesia/src/mnesia_controller.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1996-2016. All Rights Reserved.
+%% Copyright Ericsson AB 1996-2017. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -1888,7 +1888,7 @@ info_format(Tab, Size, Mem, Media) ->
StrT = mnesia_lib:pad_name(atom_to_list(Tab), 15, []),
StrS = mnesia_lib:pad_name(integer_to_list(Size), 8, []),
StrM = mnesia_lib:pad_name(integer_to_list(Mem), 8, []),
- io:format("~s: with ~s records occupying ~s ~s~n",
+ io:format("~ts: with ~s records occupying ~s ~s~n",
[StrT, StrS, StrM, Media]).
%% Handle early arrived messages
diff --git a/lib/mnesia/src/mnesia_event.erl b/lib/mnesia/src/mnesia_event.erl
index 6f7531245f..b06043bc61 100644
--- a/lib/mnesia/src/mnesia_event.erl
+++ b/lib/mnesia/src/mnesia_event.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1997-2016. All Rights Reserved.
+%% Copyright Ericsson AB 1997-2017. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
diff --git a/lib/mnesia/src/mnesia_frag.erl b/lib/mnesia/src/mnesia_frag.erl
index c6e812b36d..c39f30e140 100644
--- a/lib/mnesia/src/mnesia_frag.erl
+++ b/lib/mnesia/src/mnesia_frag.erl
@@ -58,9 +58,7 @@
-include("mnesia.hrl").
--define(OLD_HASH_MOD, mnesia_frag_old_hash).
-define(DEFAULT_HASH_MOD, mnesia_frag_hash).
-%%-define(DEFAULT_HASH_MOD, ?OLD_HASH_MOD). %% BUGBUG: New should be default
-record(frag_state,
{foreign_key,
@@ -80,7 +78,7 @@
lock(ActivityId, Opaque, {table , Tab}, LockKind) ->
case frag_names(Tab) of
[Tab] ->
- mnesia:lock(ActivityId, Opaque, {table, Tab}, LockKind);
+ mnesia:lock(ActivityId, Opaque, {table, Tab}, LockKind);
Frags ->
DeepNs = [mnesia:lock(ActivityId, Opaque, {table, F}, LockKind) ||
F <- Frags],
@@ -321,7 +319,7 @@ init_select(Tid,Opaque,Tab,Pat,Limit,LockKind) ->
{'EXIT', _} ->
mnesia:select(Tid, Opaque, Tab, Pat, Limit,LockKind);
FH ->
- FragNumbers = verify_numbers(FH,Pat),
+ FragNumbers = verify_numbers(FH,Pat),
Fun = fun(Num) ->
Name = n_to_frag_name(Tab, Num),
Node = val({Name, where_to_read}),
@@ -336,19 +334,19 @@ init_select(Tid,Opaque,Tab,Pat,Limit,LockKind) ->
end.
select_cont(_Tid,_,{frag_cont, '$end_of_table', [],_}) -> '$end_of_table';
-select_cont(Tid,Ts,{frag_cont, '$end_of_table', [{Tab,Node,Type}|Rest],Args}) ->
+select_cont(Tid,Ts,{frag_cont, '$end_of_table', [{Tab,Node,Type}|Rest],Args}) ->
{Spec,LockKind,Limit} = Args,
InitFun = fun(FixedSpec) -> mnesia:dirty_sel_init(Node,Tab,FixedSpec,Limit,Type) end,
Res = mnesia:fun_select(Tid,Ts,Tab,Spec,LockKind,Tab,InitFun,Limit,Node,Type),
frag_sel_cont(Res, Rest, Args);
-select_cont(Tid,Ts,{frag_cont, Cont, TabL, Args}) ->
+select_cont(Tid,Ts,{frag_cont, Cont, TabL, Args}) ->
frag_sel_cont(mnesia:select_cont(Tid,Ts,Cont),TabL,Args);
select_cont(Tid,Ts,Else) -> %% Not a fragmented table
mnesia:select_cont(Tid,Ts,Else).
frag_sel_cont('$end_of_table', [],_) ->
'$end_of_table';
-frag_sel_cont('$end_of_table', TabL,Args) ->
+frag_sel_cont('$end_of_table', TabL,Args) ->
{[], {frag_cont, '$end_of_table', TabL,Args}};
frag_sel_cont({Recs,Cont}, TabL,Args) ->
{Recs, {frag_cont, Cont, TabL,Args}}.
@@ -358,9 +356,9 @@ do_select(ActivityId, Opaque, Tab, MatchSpec, LockKind) ->
{'EXIT', _} ->
mnesia:select(ActivityId, Opaque, Tab, MatchSpec, LockKind);
FH ->
- FragNumbers = verify_numbers(FH,MatchSpec),
+ FragNumbers = verify_numbers(FH,MatchSpec),
Fun = fun(Num) ->
- Name = n_to_frag_name(Tab, Num),
+ Name = n_to_frag_name(Tab, Num),
Node = val({Name, where_to_read}),
mnesia:lock(ActivityId, Opaque, {table, Name}, LockKind),
{Name, Node}
@@ -398,7 +396,7 @@ do_select(ActivityId, Opaque, Tab, MatchSpec, LockKind) ->
verify_numbers(FH,MatchSpec) ->
HashState = FH#frag_state.hash_state,
- FragNumbers =
+ FragNumbers =
case FH#frag_state.hash_module of
HashMod when HashMod == ?DEFAULT_HASH_MOD ->
?DEFAULT_HASH_MOD:match_spec_to_frag_numbers(HashState, MatchSpec);
@@ -434,7 +432,7 @@ local_select(ReplyTo, Ref, RemoteNameNodes, MatchSpec) ->
end,
unlink(ReplyTo),
exit(normal).
-
+
remote_select(ReplyTo, Ref, NameNodes, MatchSpec) ->
do_remote_select(ReplyTo, Ref, NameNodes, MatchSpec).
@@ -805,22 +803,22 @@ make_deactivate(Tab) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Add a fragment to a fragmented table and fill it with half of
%% the records from one of the old fragments
-
+
make_multi_add_frag(Tab, SortedNs) when is_list(SortedNs) ->
verify_multi(Tab),
Ops = make_add_frag(Tab, SortedNs),
%% Propagate to foreigners
MoreOps = [make_add_frag(T, SortedNs) || T <- lookup_foreigners(Tab)],
- [Ops | MoreOps];
+ [Ops | MoreOps];
make_multi_add_frag(Tab, SortedNs) ->
mnesia:abort({bad_type, Tab, SortedNs}).
verify_multi(Tab) ->
FH = lookup_frag_hash(Tab),
ForeignKey = FH#frag_state.foreign_key,
- mnesia_schema:verify(undefined, ForeignKey,
- {combine_error, Tab,
+ mnesia_schema:verify(undefined, ForeignKey,
+ {combine_error, Tab,
"Op only allowed via foreign table",
{foreign_key, ForeignKey}}).
@@ -839,7 +837,7 @@ make_frag_names_and_acquire_locks(Tab, N, FragIndecies, DoNotLockN) ->
end,
FragNames = erlang:make_tuple(N, undefined),
lists:foldl(Fun, FragNames, FragIndecies).
-
+
make_add_frag(Tab, SortedNs) ->
Cs = mnesia_schema:incr_version(val({Tab, cstruct})),
mnesia_schema:ensure_active(Cs),
@@ -849,8 +847,8 @@ make_add_frag(Tab, SortedNs) ->
FragNames = make_frag_names_and_acquire_locks(Tab, N, WriteIndecies, true),
NewFrag = element(N, FragNames),
- NR = length(Cs#cstruct.ram_copies),
- ND = length(Cs#cstruct.disc_copies),
+ NR = length(Cs#cstruct.ram_copies),
+ ND = length(Cs#cstruct.disc_copies),
NDO = length(Cs#cstruct.disc_only_copies),
NExt = length(Cs#cstruct.external_copies),
NewCs = Cs#cstruct{name = NewFrag,
@@ -859,7 +857,7 @@ make_add_frag(Tab, SortedNs) ->
disc_copies = [],
disc_only_copies = [],
external_copies = []},
-
+
{NewCs2, _, _} = set_frag_nodes(NR, ND, NDO, NExt, NewCs, SortedNs, []),
[NewOp] = mnesia_schema:make_create_table(NewCs2),
@@ -944,7 +942,7 @@ do_split(FH, OldN, FragNames, [Rec | Recs], Ops) ->
Key = element(2, Rec),
NewOid = {NewFrag, Key},
OldOid = {OldFrag, Key},
- Ops2 = [{op, rec, unknown, {NewOid, [Rec], write}},
+ Ops2 = [{op, rec, unknown, {NewOid, [Rec], write}},
{op, rec, unknown, {OldOid, [OldOid], delete}} | Ops],
do_split(FH, OldN, FragNames, Recs, Ops2);
_NewFrag ->
@@ -958,7 +956,7 @@ do_split(_FH, _OldN, _FragNames, [], Ops) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Delete a fragment from a fragmented table
%% and merge its records with another fragment
-
+
make_multi_del_frag(Tab) ->
verify_multi(Tab),
Ops = make_del_frag(Tab),
@@ -1064,7 +1062,7 @@ do_merge(FH, OldN, FragNames, [Rec | Recs], Ops) ->
Key = element(2, Rec),
NewOid = {NewFrag, Key},
OldOid = {OldFrag, Key},
- Ops2 = [{op, rec, unknown, {NewOid, [Rec], write}},
+ Ops2 = [{op, rec, unknown, {NewOid, [Rec], write}},
{op, rec, unknown, {OldOid, [OldOid], delete}} | Ops],
do_merge(FH, OldN, FragNames, Recs, Ops2);
_NewFrag ->
@@ -1077,7 +1075,7 @@ do_merge(FH, OldN, FragNames, [Rec | Recs], Ops) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Add a node to the node pool of a fragmented table
-
+
make_multi_add_node(Tab, Node) ->
verify_multi(Tab),
Ops = make_add_node(Tab, Node),
@@ -1085,7 +1083,7 @@ make_multi_add_node(Tab, Node) ->
%% Propagate to foreigners
MoreOps = [make_add_node(T, Node) || T <- lookup_foreigners(Tab)],
[Ops | MoreOps].
-
+
make_add_node(Tab, Node) when is_atom(Node) ->
Pool = lookup_prop(Tab, node_pool),
case lists:member(Node, Pool) of
@@ -1114,7 +1112,7 @@ make_multi_del_node(Tab, Node) ->
%% Propagate to foreigners
MoreOps = [make_del_node(T, Node) || T <- lookup_foreigners(Tab)],
[Ops | MoreOps].
-
+
make_del_node(Tab, Node) when is_atom(Node) ->
Cs = mnesia_schema:incr_version(val({Tab, cstruct})),
mnesia_schema:ensure_active(Cs),
@@ -1147,8 +1145,8 @@ remove_node(Node, Cs) ->
case lists:member(Node, Pool) of
true ->
Pool2 = Pool -- [Node],
- Props = lists:keyreplace(node_pool, 1,
- Cs#cstruct.frag_properties,
+ Props = lists:keyreplace(node_pool, 1,
+ Cs#cstruct.frag_properties,
{node_pool, Pool2}),
{Cs#cstruct{frag_properties = Props}, true};
false ->
@@ -1180,18 +1178,10 @@ props_to_frag_hash(Tab, Props) ->
T when T == Tab ->
Foreign = mnesia_schema:pick(Tab, foreign_key, Props, must),
N = mnesia_schema:pick(Tab, n_fragments, Props, must),
-
case mnesia_schema:pick(Tab, hash_module, Props, undefined) of
undefined ->
- Split = mnesia_schema:pick(Tab, next_n_to_split, Props, must),
- Doubles = mnesia_schema:pick(Tab, n_doubles, Props, must),
- FH = {frag_hash, Foreign, N, Split, Doubles},
- HashState = ?OLD_HASH_MOD:init_state(Tab, FH),
- #frag_state{foreign_key = Foreign,
- n_fragments = N,
- hash_module = ?OLD_HASH_MOD,
- hash_state = HashState};
- HashMod ->
+ no_hash;
+ HashMod ->
HashState = mnesia_schema:pick(Tab, hash_state, Props, must),
#frag_state{foreign_key = Foreign,
n_fragments = N,
@@ -1216,13 +1206,9 @@ lookup_frag_hash(Tab) ->
case ?catch_val({Tab, frag_hash}) of
FH when is_record(FH, frag_state) ->
FH;
- {frag_hash, K, N, _S, _D} = FH ->
+ {frag_hash, _K, _N, _S, _D} ->
%% Old style. Kept for backwards compatibility.
- HashState = ?OLD_HASH_MOD:init_state(Tab, FH),
- #frag_state{foreign_key = K,
- n_fragments = N,
- hash_module = ?OLD_HASH_MOD,
- hash_state = HashState};
+ mnesia:abort({no_hash, Tab, frag_properties, frag_hash});
{'EXIT', _} ->
mnesia:abort({no_exists, Tab, frag_properties, frag_hash})
end.
@@ -1249,10 +1235,10 @@ key_pos(FH) ->
case FH#frag_state.foreign_key of
undefined ->
2;
- {_ForeignTab, Pos} ->
+ {_ForeignTab, Pos} ->
Pos
end.
-
+
%% Returns name of fragment table
key_to_frag_name({BaseTab, _} = Tab, Key) ->
N = key_to_frag_number(Tab, Key),
diff --git a/lib/mnesia/src/mnesia_frag_old_hash.erl b/lib/mnesia/src/mnesia_frag_old_hash.erl
deleted file mode 100644
index b246c76236..0000000000
--- a/lib/mnesia/src/mnesia_frag_old_hash.erl
+++ /dev/null
@@ -1,133 +0,0 @@
-%%
-%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 2002-2016. All Rights Reserved.
-%%
-%% Licensed under the Apache License, Version 2.0 (the "License");
-%% you may not use this file except in compliance with the License.
-%% You may obtain a copy of the License at
-%%
-%% http://www.apache.org/licenses/LICENSE-2.0
-%%
-%% Unless required by applicable law or agreed to in writing, software
-%% distributed under the License is distributed on an "AS IS" BASIS,
-%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-%% See the License for the specific language governing permissions and
-%% limitations under the License.
-%%
-%% %CopyrightEnd%
-%%
-
-%%
-%%%----------------------------------------------------------------------
-%%% Purpose : Implements hashing functionality for fragmented tables
-%%%----------------------------------------------------------------------
-
--module(mnesia_frag_old_hash).
-%%-behaviour(mnesia_frag_hash).
-
--compile({nowarn_deprecated_function, {erlang,hash,2}}).
-
-%% Hashing callback functions
--export([
- init_state/2,
- add_frag/1,
- del_frag/1,
- key_to_frag_number/2,
- match_spec_to_frag_numbers/2
- ]).
-
--record(old_hash_state,
- {n_fragments,
- next_n_to_split,
- n_doubles}).
-
-%% Old style. Kept for backwards compatibility.
--record(frag_hash,
- {foreign_key,
- n_fragments,
- next_n_to_split,
- n_doubles}).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-init_state(_Tab, InitialState) when InitialState == undefined ->
- #old_hash_state{n_fragments = 1,
- next_n_to_split = 1,
- n_doubles = 0};
-init_state(_Tab, FH) when is_record(FH, frag_hash) ->
- %% Old style. Kept for backwards compatibility.
- #old_hash_state{n_fragments = FH#frag_hash.n_fragments,
- next_n_to_split = FH#frag_hash.next_n_to_split,
- n_doubles = FH#frag_hash.n_doubles}.
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-add_frag(State) when is_record(State, old_hash_state) ->
- SplitN = State#old_hash_state.next_n_to_split,
- P = SplitN + 1,
- L = State#old_hash_state.n_doubles,
- NewN = State#old_hash_state.n_fragments + 1,
- State2 = case trunc(math:pow(2, L)) + 1 of
- P2 when P2 == P ->
- State#old_hash_state{n_fragments = NewN,
- next_n_to_split = 1,
- n_doubles = L + 1};
- _ ->
- State#old_hash_state{n_fragments = NewN,
- next_n_to_split = P}
- end,
- {State2, [SplitN], [NewN]}.
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-del_frag(State) when is_record(State, old_hash_state) ->
- P = State#old_hash_state.next_n_to_split - 1,
- L = State#old_hash_state.n_doubles,
- N = State#old_hash_state.n_fragments,
- if
- P < 1 ->
- L2 = L - 1,
- MergeN = trunc(math:pow(2, L2)),
- State2 = State#old_hash_state{n_fragments = N - 1,
- next_n_to_split = MergeN,
- n_doubles = L2},
- {State2, [N], [MergeN]};
- true ->
- MergeN = P,
- State2 = State#old_hash_state{n_fragments = N - 1,
- next_n_to_split = MergeN},
- {State2, [N], [MergeN]}
- end.
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-key_to_frag_number(State, Key) when is_record(State, old_hash_state) ->
- L = State#old_hash_state.n_doubles,
- A = erlang:hash(Key, trunc(math:pow(2, L))),
- P = State#old_hash_state.next_n_to_split,
- if
- A < P ->
- erlang:hash(Key, trunc(math:pow(2, L + 1)));
- true ->
- A
- end.
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-match_spec_to_frag_numbers(State, MatchSpec) when is_record(State, old_hash_state) ->
- case MatchSpec of
- [{HeadPat, _, _}] when is_tuple(HeadPat), tuple_size(HeadPat) > 2 ->
- KeyPat = element(2, HeadPat),
- case has_var(KeyPat) of
- false ->
- [key_to_frag_number(State, KeyPat)];
- true ->
- lists:seq(1, State#old_hash_state.n_fragments)
- end;
- _ ->
- lists:seq(1, State#old_hash_state.n_fragments)
- end.
-
-has_var(Pat) ->
- mnesia:has_var(Pat).
diff --git a/lib/mnesia/src/mnesia_kernel_sup.erl b/lib/mnesia/src/mnesia_kernel_sup.erl
index c9af5c460a..a761d5eed0 100644
--- a/lib/mnesia/src/mnesia_kernel_sup.erl
+++ b/lib/mnesia/src/mnesia_kernel_sup.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1997-2016. All Rights Reserved.
+%% Copyright Ericsson AB 1997-2017. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -43,7 +43,6 @@ init([]) ->
worker_spec(mnesia_recover, timer:minutes(3), [gen_server]),
worker_spec(mnesia_tm, timer:seconds(30), ProcLib),
supervisor_spec(mnesia_checkpoint_sup),
- supervisor_spec(mnesia_snmp_sup),
worker_spec(mnesia_controller, timer:seconds(3), [gen_server]),
worker_spec(mnesia_late_loader, timer:seconds(3), ProcLib)
],
diff --git a/lib/mnesia/src/mnesia_lib.erl b/lib/mnesia/src/mnesia_lib.erl
index 10e232c800..1fdc656600 100644
--- a/lib/mnesia/src/mnesia_lib.erl
+++ b/lib/mnesia/src/mnesia_lib.erl
@@ -1192,25 +1192,15 @@ db_select(Storage, Tab, Pat) ->
end.
db_select_init({ext, Alias, Mod}, Tab, Pat, Limit) ->
- case Mod:select(Alias, Tab, Pat, Limit) of
- {Matches, Continuation} when is_list(Matches) ->
- {Matches, {Alias, Continuation}};
- R ->
- R
- end;
+ Mod:select(Alias, Tab, Pat, Limit);
db_select_init(disc_only_copies, Tab, Pat, Limit) ->
dets:select(Tab, Pat, Limit);
db_select_init(_, Tab, Pat, Limit) ->
ets:select(Tab, Pat, Limit).
-db_select_cont({ext, Alias, Mod}, Cont0, Ms) ->
+db_select_cont({ext, _Alias, Mod}, Cont0, Ms) ->
Cont = Mod:repair_continuation(Cont0, Ms),
- case Mod:select(Cont) of
- {Matches, Continuation} when is_list(Matches) ->
- {Matches, {Alias, Continuation}};
- R ->
- R
- end;
+ Mod:select(Cont);
db_select_cont(disc_only_copies, Cont0, Ms) ->
Cont = dets:repair_continuation(Cont0, Ms),
dets:select(Cont);
diff --git a/lib/mnesia/src/mnesia_monitor.erl b/lib/mnesia/src/mnesia_monitor.erl
index ab78c9b13e..22a24b6dc9 100644
--- a/lib/mnesia/src/mnesia_monitor.erl
+++ b/lib/mnesia/src/mnesia_monitor.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1996-2016. All Rights Reserved.
+%% Copyright Ericsson AB 1996-2017. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -169,7 +169,7 @@ check_protocol([{Node, {accept, Mon, Version, Protocol}} | Tail], Protocols) ->
verbose("Failed to connect with ~p. ~p protocols rejected. "
"expected version = ~p, expected protocol = ~p~n",
[Node, Protocols, Version, Protocol]),
- unlink(Mon), % Get rid of unneccessary link
+ unlink(Mon), % Get rid of unnecessary link
check_protocol(Tail, Protocols)
end;
check_protocol([{Node, {reject, _Mon, Version, Protocol}} | Tail], Protocols) ->
diff --git a/lib/mnesia/src/mnesia_schema.erl b/lib/mnesia/src/mnesia_schema.erl
index 0e4017e4c3..f71ee26d7c 100644
--- a/lib/mnesia/src/mnesia_schema.erl
+++ b/lib/mnesia/src/mnesia_schema.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1996-2016. All Rights Reserved.
+%% Copyright Ericsson AB 1996-2017. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -866,18 +866,18 @@ list2cs(List, ExtTypes) when is_list(List) ->
is_list(DetsOpts) orelse mnesia:abort({badarg, Name, {dets, DetsOpts}}),
[CheckProp(Prop, BadDetsOpts) || Prop <- DetsOpts],
- case lists:keymember(mnesia, 1, application:which_applications()) of
- true ->
- Keys = check_keys(Name, List),
- check_duplicates(Name, Keys);
- false ->
+ case whereis(mnesia_controller) of
+ undefined ->
%% check_keys/2 cannot be executed when mnesia is not
%% running, due to it not being possible to read what ext
%% backends are loaded.
- %%% this doesn't work - disabled for now:
- %%%Keys = check_keys(Name, List, record_info(fields, cstruct)),
- %%%check_duplicates(Name, Keys)
- ignore
+ %% this doesn't work - disabled for now:
+ %%Keys = check_keys(Name, List, record_info(fields, cstruct)),
+ %%check_duplicates(Name, Keys)
+ ignore;
+ Pid when is_pid(Pid) ->
+ Keys = check_keys(Name, List),
+ check_duplicates(Name, Keys)
end,
Cs0 = #cstruct{name = Name,
@@ -1941,7 +1941,7 @@ make_change_table_copy_type(Tab, Node, ToS) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% change index functions ....
-%% Pos is allready added by 1 in both of these functions
+%% Pos is already added by 1 in both of these functions
add_table_index(Tab, Pos) ->
schema_transaction(fun() -> do_add_table_index(Tab, Pos) end).
diff --git a/lib/mnesia/src/mnesia_snmp_sup.erl b/lib/mnesia/src/mnesia_snmp_sup.erl
deleted file mode 100644
index ed579d01c5..0000000000
--- a/lib/mnesia/src/mnesia_snmp_sup.erl
+++ /dev/null
@@ -1,43 +0,0 @@
-%%
-%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 1997-2016. All Rights Reserved.
-%%
-%% Licensed under the Apache License, Version 2.0 (the "License");
-%% you may not use this file except in compliance with the License.
-%% You may obtain a copy of the License at
-%%
-%% http://www.apache.org/licenses/LICENSE-2.0
-%%
-%% Unless required by applicable law or agreed to in writing, software
-%% distributed under the License is distributed on an "AS IS" BASIS,
-%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-%% See the License for the specific language governing permissions and
-%% limitations under the License.
-%%
-%% %CopyrightEnd%
-%%
-
-%%
--module(mnesia_snmp_sup).
-
--behaviour(supervisor).
-
--export([start/0, init/1]).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% top supervisor callback functions
-
-start() ->
- supervisor:start_link({local, ?MODULE}, ?MODULE, []).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% sub supervisor callback functions
-
-init([]) ->
- Flags = {simple_one_for_one, 0, timer:hours(24)}, % Trust the top supervisor
- MFA = {mnesia_snmp_hook, start, []},
- Modules = [?MODULE, mnesia_snmp_hook, supervisor],
- KillAfter = mnesia_kernel_sup:supervisor_timeout(timer:seconds(3)),
- Workers = [{?MODULE, MFA, transient, KillAfter, worker, Modules}],
- {ok, {Flags, Workers}}.
diff --git a/lib/mnesia/src/mnesia_sup.erl b/lib/mnesia/src/mnesia_sup.erl
index 4aece81308..3e5792900b 100644
--- a/lib/mnesia/src/mnesia_sup.erl
+++ b/lib/mnesia/src/mnesia_sup.erl
@@ -23,39 +23,21 @@
-module(mnesia_sup).
--behaviour(application).
-behaviour(supervisor).
--export([start/0, start/2, init/1, stop/1, start_event/0, kill/0]).
+-export([start_link/1, init/1, start_event/0, kill/0]).
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% application and suprvisor callback functions
-
-start(normal, Args) ->
- SupName = {local,?MODULE},
- case supervisor:start_link(SupName, ?MODULE, [Args]) of
- {ok, Pid} ->
- {ok, Pid, {normal, Args}};
- Error ->
- Error
- end;
-start(_, _) ->
- {error, badarg}.
-
-start() ->
- SupName = {local,?MODULE},
- supervisor:start_link(SupName, ?MODULE, []).
+start_link(Args) ->
+ supervisor:start_link({local,?MODULE}, ?MODULE, [Args]).
-stop(_StartArgs) ->
- ok.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% supervisor callback functions
-init([]) -> % Supervisor
- init();
-init([[]]) -> % Application
+init([[]]) ->
init();
init(BadArg) ->
{error, {badarg, BadArg}}.
-
+
init() ->
Flags = {one_for_all, 0, 3600}, % Should be rest_for_one policy
@@ -124,4 +106,3 @@ ensure_dead(Name) ->
timer:sleep(10),
ensure_dead(Name)
end.
-
diff --git a/lib/mnesia/test/ext_test.erl b/lib/mnesia/test/ext_test.erl
index 3d1cc40c09..ad32245a11 100644
--- a/lib/mnesia/test/ext_test.erl
+++ b/lib/mnesia/test/ext_test.erl
@@ -233,5 +233,5 @@ select_1({Acc, C}) ->
select(ext_ets, Tab, Ms, Limit) when is_integer(Limit); Limit =:= infinity ->
ets:select(mnesia_lib:val({?MODULE,Tab}), Ms, Limit).
-repair_continuation({Alias, Cont}, Ms) ->
- {Alias, ets:repair_continuation(Cont, Ms)}.
+repair_continuation(Cont, Ms) ->
+ ets:repair_continuation(Cont, Ms).
diff --git a/lib/mnesia/test/mnesia_evil_backup.erl b/lib/mnesia/test/mnesia_evil_backup.erl
index 044cf501fd..0fa72c4305 100644
--- a/lib/mnesia/test/mnesia_evil_backup.erl
+++ b/lib/mnesia/test/mnesia_evil_backup.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1998-2016. All Rights Reserved.
+%% Copyright Ericsson AB 1998-2017. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
diff --git a/lib/mnesia/vsn.mk b/lib/mnesia/vsn.mk
index e272a469bb..81b15d65db 100644
--- a/lib/mnesia/vsn.mk
+++ b/lib/mnesia/vsn.mk
@@ -1 +1 @@
-MNESIA_VSN = 4.14.3
+MNESIA_VSN = 4.15