aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mnesia
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mnesia')
-rw-r--r--lib/mnesia/src/Makefile2
-rw-r--r--lib/mnesia/src/mnesia.app.src2
-rw-r--r--lib/mnesia/src/mnesia.erl1
-rw-r--r--lib/mnesia/src/mnesia_backend_type.erl115
-rw-r--r--lib/mnesia/src/mnesia_ext_sup.erl59
-rw-r--r--lib/mnesia/src/mnesia_sup.erl8
6 files changed, 186 insertions, 1 deletions
diff --git a/lib/mnesia/src/Makefile b/lib/mnesia/src/Makefile
index dae0df76f3..3134a15138 100644
--- a/lib/mnesia/src/Makefile
+++ b/lib/mnesia/src/Makefile
@@ -43,6 +43,7 @@ RELSYSDIR = $(RELEASE_PATH)/lib/mnesia-$(VSN)
# ----------------------------------------------------
MODULES= \
mnesia \
+ mnesia_backend_type \
mnesia_backup \
mnesia_bup \
mnesia_checkpoint \
@@ -50,6 +51,7 @@ MODULES= \
mnesia_controller \
mnesia_dumper\
mnesia_event \
+ mnesia_ext_sup \
mnesia_frag \
mnesia_frag_hash \
mnesia_frag_old_hash \
diff --git a/lib/mnesia/src/mnesia.app.src b/lib/mnesia/src/mnesia.app.src
index c78a7cba1e..006ad4bac1 100644
--- a/lib/mnesia/src/mnesia.app.src
+++ b/lib/mnesia/src/mnesia.app.src
@@ -3,6 +3,7 @@
{vsn, "%VSN%"},
{modules, [
mnesia,
+ mnesia_backend_type,
mnesia_backup,
mnesia_bup,
mnesia_checkpoint,
@@ -10,6 +11,7 @@
mnesia_controller,
mnesia_dumper,
mnesia_event,
+ mnesia_ext_sup,
mnesia_frag,
mnesia_frag_hash,
mnesia_frag_old_hash,
diff --git a/lib/mnesia/src/mnesia.erl b/lib/mnesia/src/mnesia.erl
index 2fdc7afacd..d0dc9eb13b 100644
--- a/lib/mnesia/src/mnesia.erl
+++ b/lib/mnesia/src/mnesia.erl
@@ -297,6 +297,7 @@ ms() ->
%% Keep these last in the list, so
%% mnesia_sup kills these last
+ mnesia_ext_sup,
mnesia_monitor,
mnesia_event
].
diff --git a/lib/mnesia/src/mnesia_backend_type.erl b/lib/mnesia/src/mnesia_backend_type.erl
new file mode 100644
index 0000000000..4791b82a01
--- /dev/null
+++ b/lib/mnesia/src/mnesia_backend_type.erl
@@ -0,0 +1,115 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 1996-2015. 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%
+%%
+
+%%
+%% Behaviour definition for mnesia backend types.
+%%
+
+%%%header_doc_include
+
+-module(mnesia_backend_type).
+
+-export([behaviour_info/1]).
+
+%%%header_doc_include
+
+%%%impl_doc_include
+
+%% Note that mnesia considers all callbacks mandatory!!
+%%
+behaviour_info(callbacks) ->
+ [
+ {add_aliases, 1}, % (Aliases) -> ok
+ {check_definition, 4}, % (TypeAlias, Tab, Nodes, Properties) -> ok
+ {close_table, 2}, % (TypeAlias, Tab) -> ok
+ {create_table, 3}, % (TypeAlias, Tab, Properties) -> ok
+ {delete, 3}, % (TypeAlias, Tab, Key) -> true | ok
+ {delete_table, 2}, % (TypeAlias, Tab) -> ok
+ {first, 2}, % (TypeAlias, Tab) -> Key::Term | '$end_of_table'
+ {fixtable, 3}, % (TypeAlias, Tab, Bool) -> ok | true
+ {last, 2}, % (TypeAlias, Tab) -> Key::Term | '$end_of_table'
+ {index_is_consistent,3}, % (TypeAlias, IxTag, Bool) -> ok
+ {init_backend, 0}, % () -> ok
+ {info, 3}, % (TypeAlias, Tab, Item) -> Term
+ {insert, 3}, % (TypeAlias, Tab, Object) -> ok
+ {lookup, 3}, % (TypeAlias, Tab, Key) -> [Objects]
+ {is_index_consistent,2}, % (TypeAlias, IxTag) -> Bool
+ {load_table, 4}, % (TypeAlias, Tab, Reason, CsList) -> ok
+ {match_delete, 3}, % (TypeAlias, Tab, Pattern) -> ok
+ {next, 3}, % (TypeAlias, Tab, Key) -> Key::Term | '$end_of_table'
+ {prev, 3}, % (TypeAlias, Tab, Key) -> Key::Term | '$end_of_table'
+ {receiver_first_message, 4}, % (Sender, FirstMsg, Alias, Tab) -> {Size, State}
+ {receive_data, 5}, % (Data, Alias, Name, Sender, State) -> {more, State} | {{more, Msg}, State}
+ {receive_done, 4}, % (Alias, Tab, Sender, State) -> ok
+ {real_suffixes, 0}, % () -> [FileSuffix]
+ {remove_aliases, 1}, % (Aliases) -> ok
+ {repair_continuation, 2}, % (Continuation, MatchSpec) -> Continuation
+ {select, 1}, % (Continuation) -> {[Match], Continuation'} | '$end_of_table'
+ {select, 3}, % (TypeAlias, Tab, Pattern) -> {[Match], Continuation'} | '$end_of_table'
+ {select, 4}, % (TypeAlias, Tab, MatchSpec, Limit) {[Match], Continuation'} | '$end_of_table'
+ {sender_init, 4}, % (TypeAlias, Tab, LoadReason, Pid) ->
+ % {standard, Init(), Chunk()} | {Init(), Chunk()}
+ {semantics, 2}, % (TypeAlias, storage | types | index_fun | index_types) ->
+ % ram_copies | disc_copies, set | ordered_set | bag, fun(), ordered | bag
+ {slot, 3}, % (TypeAlias, Tab, Pos) -> '$end_of_table' | Objects | {error, Reason}
+ {sync_close_table, 2}, % (TypeAlias, Tab) -> ok
+ {tmp_suffixes, 0}, % () -> [FileSuffix]
+ {update_counter, 4}, % (TypeAlias, Tab, Counter, Val) -> NewVal
+ {validate_key, 6}, % (TypeAlias, Tab, RecName, Arity, Type, Key) -> {RecName, Arity, Type}
+ {validate_record, 6} % (TypeAlias, Tab, RecName, Arity, Type, Obj) -> {RecName, Arity, Type}
+ ].
+
+%%%impl_doc_include
+
+%% -type tab() :: atom().
+%% -type alias() :: atom().
+%% -type rec_name() :: atom().
+%% -type type() :: set | bag | ordered_set.
+%% -type proplist() :: [{atom(), any()}].
+%% -type key() :: any().
+%% -type db_object() :: tuple().
+
+%% -type matchspec() :: ets:match_spec().
+%% -type limit() :: integer() | infinity.
+
+%% -type cont_fun() :: any().
+%% -type cont() :: '$end_of_table' | cont_fun().
+
+%% -callback check_definition(alias(), tab(), [node()], proplist()) -> ok.
+%% -callback create_table(alias(), tab(), proplist()) -> tab().
+%% -callback load_table(alias(), tab(), any()) -> ok.
+%% -callback delete_table(alias(), tab()) -> ok.
+%% -callback first(alias(), tab()) -> key().
+%% -callback last(alias(), tab()) -> key().
+%% -callback next(alias(), tab(), key()) -> key().
+%% -callback prev(alias(), tab(), key()) -> key().
+%% -callback insert(alias(), tab(), db_object()) -> ok.
+%% -callback lookup(alias(), tab(), key()) -> [db_object()].
+%% -callback delete(alias(), tab(), key()) -> ok.
+%% -callback update_counter(alias(), tab(), key(), integer()) -> integer().
+%% -callback select(cont()) -> {list(), cont()}.
+%% -callback select(alias(), tab(), matchspec()) -> list() | '$end_of_table'.
+%% -callback select(alias(), tab(), matchspec(), limit()) -> {list(), cont()}.
+%% -callback slot(alias(), tab(), integer()) -> key().
+%% -callback validate_key(alias(), tab(), rec_name(), arity(), type(), key()) ->
+%% {rec_name(), arity(), type()}.
+%% -callback validate_record(alias(),tab(),rec_name(),arity(),type(),db_obj()) ->
+%% {rec_name(), arity(), type()}.
+%% -callback repair_continuation(cont(), matchspec()) -> cont().
diff --git a/lib/mnesia/src/mnesia_ext_sup.erl b/lib/mnesia/src/mnesia_ext_sup.erl
new file mode 100644
index 0000000000..3e6c72161c
--- /dev/null
+++ b/lib/mnesia/src/mnesia_ext_sup.erl
@@ -0,0 +1,59 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 1996-2015. 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%
+%%
+
+%%
+%% This module implements a supervisor for external (plug-in) processes
+
+-module(mnesia_ext_sup).
+-behaviour(supervisor).
+
+-export([start/0,
+ init/1,
+ start_proc/4, start_proc/5,
+ stop_proc/1]).
+
+-define(SHUTDOWN, 120000). % 2 minutes
+
+start() ->
+ supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+start_proc(Name, M, F, A) ->
+ start_proc(Name, M, F, A, []).
+
+start_proc(Name, M, F, A, Opts) ->
+ [Restart, Shutdown, Type, Modules] =
+ [proplists:get_value(K, Opts, Default)
+ || {K, Default} <- [{restart, transient},
+ {shutdown, ?SHUTDOWN},
+ {type, worker},
+ {modules, [M]}]],
+ case supervisor:start_child(
+ ?MODULE, {Name, {M,F,A}, Restart, Shutdown, Type, Modules}) of
+ {error, already_present} ->
+ supervisor:restart_child(?MODULE, Name);
+ Other ->
+ Other
+ end.
+
+stop_proc(Name) ->
+ supervisor:terminate_child(?MODULE, Name).
+
+init(_) ->
+ {ok, {{one_for_all, 10, 60}, []}}.
diff --git a/lib/mnesia/src/mnesia_sup.erl b/lib/mnesia/src/mnesia_sup.erl
index 3a9360aa6d..b8dd4f48a6 100644
--- a/lib/mnesia/src/mnesia_sup.erl
+++ b/lib/mnesia/src/mnesia_sup.erl
@@ -60,9 +60,10 @@ init() ->
Flags = {one_for_all, 0, 3600}, % Should be rest_for_one policy
Event = event_procs(),
+ Ext = ext_procs(),
Kernel = kernel_procs(),
- {ok, {Flags, Event ++ Kernel}}.
+ {ok, {Flags, Event ++ Ext ++ Kernel}}.
event_procs() ->
KillAfter = timer:seconds(30),
@@ -75,6 +76,11 @@ kernel_procs() ->
KA = infinity,
[{K, {K, start, []}, permanent, KA, supervisor, [K, supervisor]}].
+ext_procs() ->
+ K = mnesia_ext_sup,
+ KA = infinity,
+ [{K, {K, start, []}, permanent, KA, supervisor, [K, supervisor]}].
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% event handler