aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mnesia/src/mnesia_controller.erl
diff options
context:
space:
mode:
authorUlf Wiger <[email protected]>2013-11-20 18:21:44 +0100
committerRichard Carlsson <[email protected]>2014-12-22 22:44:06 +0100
commitfefb2d78cb10606f83ad4010fee6a8be4d4191f2 (patch)
tree15565ad48081f302d930cb504d9747259c4646c1 /lib/mnesia/src/mnesia_controller.erl
parent85112014bd136055b56e6ec5218f82f74951e0c6 (diff)
downloadotp-fefb2d78cb10606f83ad4010fee6a8be4d4191f2.tar.gz
otp-fefb2d78cb10606f83ad4010fee6a8be4d4191f2.tar.bz2
otp-fefb2d78cb10606f83ad4010fee6a8be4d4191f2.zip
Make Mnesia DCD dump behaviour available via API
If a DCD dump is desired on-demand, use the function mnesia_controller:snapshot_dcd(Tables). Tables must be a list of tables that have a local disc_copy, otherwise an error will be returned. Once the operation actually executes, any table that doesn't have a local disc_copy is ignored. Specifically, the dump_log worker record has been changed to allow an arity-0 fun instead of the default log dump. This fun will be executed as if it were a normal log dump, and must return 'dumped'. This could also be used to e.g. insert a backup operation between log dumps.
Diffstat (limited to 'lib/mnesia/src/mnesia_controller.erl')
-rw-r--r--lib/mnesia/src/mnesia_controller.erl29
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/mnesia/src/mnesia_controller.erl b/lib/mnesia/src/mnesia_controller.erl
index a83e55ac62..2c2f284abf 100644
--- a/lib/mnesia/src/mnesia_controller.erl
+++ b/lib/mnesia/src/mnesia_controller.erl
@@ -51,6 +51,7 @@
force_load_table/1,
async_dump_log/1,
sync_dump_log/1,
+ snapshot_dcd/1,
connect_nodes/1,
connect_nodes/2,
wait_for_schema_commit_lock/0,
@@ -139,7 +140,8 @@ max_loaders() ->
-record(block_controller, {owner}).
-record(dump_log, {initiated_by,
- opt_reply_to
+ opt_reply_to,
+ operation = dump_log
}).
-record(net_load, {table,
@@ -201,6 +203,15 @@ async_dump_log(InitBy) ->
?SERVER_NAME ! {async_dump_log, InitBy},
ok.
+snapshot_dcd(Tables) when is_list(Tables) ->
+ case [T || T <- Tables,
+ mnesia_lib:storage_type_at_node(node(), T) =/= disc_copies] of
+ [] ->
+ call({snapshot_dcd, Tables});
+ BadTabs ->
+ {error, {not_disc_copies, BadTabs}}
+ end.
+
%% Wait for tables to be active
%% If needed, we will wait for Mnesia to start
%% If Mnesia stops, we will wait for Mnesia to restart
@@ -647,6 +658,15 @@ handle_call({sync_dump_log, InitBy}, From, State) ->
State2 = add_worker(Worker, State),
noreply(State2);
+handle_call({snapshot_dcd, Tables}, From, State) ->
+ Worker = #dump_log{initiated_by = user,
+ opt_reply_to = From,
+ operation = fun() ->
+ mnesia_dumper:snapshot_dcd(Tables)
+ end},
+ State2 = add_worker(Worker, State),
+ noreply(State2);
+
handle_call(wait_for_schema_commit_lock, From, State) ->
Worker = #schema_commit_lock{owner = From},
State2 = add_worker(Worker, State),
@@ -2083,7 +2103,12 @@ start_remote_sender(Node, Tab, Receiver, Storage) ->
dump_and_reply(ReplyTo, Worker) ->
%% No trap_exit, die intentionally instead
- Res = mnesia_dumper:opt_dump_log(Worker#dump_log.initiated_by),
+ Res = case Worker#dump_log.operation of
+ dump_log ->
+ mnesia_dumper:opt_dump_log(Worker#dump_log.initiated_by);
+ F when is_function(F, 0) ->
+ F()
+ end,
ReplyTo ! #dumper_done{worker_pid = self(),
worker_res = Res},
unlink(ReplyTo),