From 82c090488eb76d16e8b828bb8f050afd0949e4c4 Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Sun, 9 May 2010 12:15:56 +0200 Subject: Enable continuous monitoring of mnesia overload status Mnesia currently issues an event whenever it detects an overload condition. It recognizes two different types of overload: - whenever the message queue of mnesia_tm process grows large - when a log dump interval triggers before the previous dump is done These events could be used to trigger a load regulation mechanism to reduce the load until the condition seizes. The missing piece is that there is no facility to ask mnesia whether the overload condition still exists. This patch implements a couple of functions in mnesia_lib that can be used to sample the overload status. It has been tested in a load regulator component being developed by Erlang Solutions. No mnesia test suites have been run, since they are not available. No documentation has been updated. The functions in mnesia_lib are at any rate undocumented (as are all other functions in that module). A decision would have to be made about whether to provide a documented API on top of these functions. The internal state record of mnesia_recover has been modified. For this reason, a code change hook has been provided. --- lib/mnesia/src/mnesia_lib.erl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'lib/mnesia/src/mnesia_lib.erl') diff --git a/lib/mnesia/src/mnesia_lib.erl b/lib/mnesia/src/mnesia_lib.erl index dba808e66e..168e225289 100644 --- a/lib/mnesia/src/mnesia_lib.erl +++ b/lib/mnesia/src/mnesia_lib.erl @@ -113,6 +113,9 @@ mkcore/1, not_active_here/1, other_val/2, + overload_read/0, + overload_read/1, + overload_set/2, pad_name/3, random_time/2, read_counter/1, @@ -551,6 +554,33 @@ cs_to_nodes(Cs) -> Cs#cstruct.disc_only_copies ++ Cs#cstruct.disc_copies ++ Cs#cstruct.ram_copies. + +overload_types() -> + [mnesia_tm, mnesia_dump_log]. + +valid_overload_type(T) -> + case lists:member(T, overload_types()) of + false -> + erlang:error(bad_type); + true -> + true + end. + +overload_set(Type, Bool) when is_boolean(Bool) -> + valid_overload_type(Type), + set({overload, Type}, Bool). + +overload_read() -> + [{T, overload_read(T)} || T <- overload_types()]. + +overload_read(T) -> + case ?catch_val({overload, T}) of + {'EXIT',_} -> + valid_overload_type(T), + false; + Flag when is_boolean(Flag) -> + Flag + end. dist_coredump() -> dist_coredump(all_nodes()). -- cgit v1.2.3