diff options
author | Matthias Radestock <matthias@lshift.net> | 2009-01-08 22:10:10 +0000 |
---|---|---|
committer | Matthias Radestock <matthias@lshift.net> | 2009-01-08 22:10:10 +0000 |
commit | e89fa86a968abf449683e686f7110c869a50a698 (patch) | |
tree | 87ec3128454cd12d890c6523b95e1e7bf720e2c3 | |
parent | 6d7792714815e494cb63aec8ee86894e12f5e4d7 (diff) | |
parent | 6ebf31bd90a044cec95301d0bb9008267ca9c3ed (diff) | |
download | rabbitmq-server-e89fa86a968abf449683e686f7110c869a50a698.tar.gz |
merge bug18557 into bug20097
-rw-r--r-- | ebin/rabbit.app | 4 | ||||
-rw-r--r-- | src/rabbit.erl | 32 | ||||
-rw-r--r-- | src/rabbit_alarm.erl | 22 | ||||
-rw-r--r-- | src/rabbit_channel.erl | 18 | ||||
-rw-r--r-- | src/rabbit_error_logger_file_h.erl | 2 | ||||
-rw-r--r-- | src/rabbit_exchange.erl | 6 | ||||
-rw-r--r-- | src/rabbit_misc.erl | 32 | ||||
-rw-r--r-- | src/rabbit_mnesia.erl | 4 | ||||
-rw-r--r-- | src/rabbit_sasl_report_file_h.erl | 2 |
9 files changed, 67 insertions, 55 deletions
diff --git a/ebin/rabbit.app b/ebin/rabbit.app index e377a33a..64afb5ff 100644 --- a/ebin/rabbit.app +++ b/ebin/rabbit.app @@ -51,8 +51,8 @@ {applications, [kernel, stdlib, sasl, mnesia, os_mon]}, {mod, {rabbit, []}}, {env, [{tcp_listeners, [{"0.0.0.0", 5672}]}, - {extra_startup_steps, []}, + {extra_startup_steps, []}, {default_user, <<"guest">>}, {default_pass, <<"guest">>}, {default_vhost, <<"/">>}, - {memory_alarms, false}]}]}. + {memory_alarms, auto}]}]}. diff --git a/src/rabbit.erl b/src/rabbit.erl index 41064c77..30b8c394 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -75,14 +75,14 @@ start() -> try ok = ensure_working_log_handlers(), ok = rabbit_mnesia:ensure_mnesia_dir(), - ok = start_applications(?APPS) + ok = rabbit_misc:start_applications(?APPS) after %%give the error loggers some time to catch up timer:sleep(100) end. stop() -> - ok = stop_applications(?APPS). + ok = rabbit_misc:stop_applications(?APPS). stop_and_halt() -> spawn(fun () -> @@ -109,34 +109,6 @@ rotate_logs(BinarySuffix) -> %%-------------------------------------------------------------------- -manage_applications(Iterate, Do, Undo, SkipError, ErrorTag, Apps) -> - Iterate(fun (App, Acc) -> - case Do(App) of - ok -> [App | Acc]; - {error, {SkipError, _}} -> Acc; - {error, Reason} -> - lists:foreach(Undo, Acc), - throw({error, {ErrorTag, App, Reason}}) - end - end, [], Apps), - ok. - -start_applications(Apps) -> - manage_applications(fun lists:foldl/3, - fun application:start/1, - fun application:stop/1, - already_started, - cannot_start_application, - Apps). - -stop_applications(Apps) -> - manage_applications(fun lists:foldr/3, - fun application:stop/1, - fun application:start/1, - not_started, - cannot_stop_application, - Apps). - start(normal, []) -> {ok, SupPid} = rabbit_sup:start_link(), diff --git a/src/rabbit_alarm.erl b/src/rabbit_alarm.erl index 7bbed8b7..875624ba 100644 --- a/src/rabbit_alarm.erl +++ b/src/rabbit_alarm.erl @@ -40,6 +40,9 @@ -define(MEMSUP_CHECK_INTERVAL, 1000). +%% OSes on which we know memory alarms to be trustworthy +-define(SUPPORTED_OS, [{unix, linux}]). + -record(alarms, {alertees, system_memory_high_watermark = false}). %%---------------------------------------------------------------------------- @@ -47,18 +50,23 @@ -ifdef(use_specs). -type(mfa_tuple() :: {atom(), atom(), list()}). --spec(start/1 :: (bool()) -> 'ok'). +-spec(start/1 :: (bool() | 'auto') -> 'ok'). -spec(stop/0 :: () -> 'ok'). -spec(register/2 :: (pid(), mfa_tuple()) -> 'ok'). - + -endif. %%---------------------------------------------------------------------------- start(MemoryAlarms) -> - ok = alarm_handler:add_alarm_handler(?MODULE, [MemoryAlarms]), + EnableAlarms = case MemoryAlarms of + true -> true; + false -> false; + auto -> lists:member(os:type(), ?SUPPORTED_OS) + end, + ok = alarm_handler:add_alarm_handler(?MODULE, [EnableAlarms]), case whereis(memsup) of - undefined -> if MemoryAlarms -> ok = start_memsup(), + undefined -> if EnableAlarms -> ok = start_memsup(), ok = adjust_memsup_interval(); true -> ok end; @@ -93,7 +101,7 @@ handle_call({register, Pid, HighMemMFA}, end, NewAlertees = dict:store(Pid, HighMemMFA, Alertess), {ok, ok, State#alarms{alertees = NewAlertees}}; - + handle_call(_Request, State) -> {ok, not_understood, State}. @@ -127,7 +135,7 @@ code_change(_OldVsn, State, _Extra) -> %%---------------------------------------------------------------------------- start_memsup() -> - Mod = case os:type() of + Mod = case os:type() of %% memsup doesn't take account of buffers or cache when %% considering "free" memory - therefore on Linux we can %% get memory alarms very easily without any pressure @@ -135,7 +143,7 @@ start_memsup() -> %% our own simple memory monitor. %% {unix, linux} -> rabbit_memsup_linux; - + %% Start memsup programmatically rather than via the %% rabbitmq-server script. This is not quite the right %% thing to do as os_mon checks to see if memsup is diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index 304275c4..513d3050 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -112,16 +112,14 @@ init(ProxyPid, [ReaderPid, WriterPid, Username, VHost]) -> consumer_mapping = dict:new()}. handle_message({method, Method, Content}, State) -> - try - case handle_method(Method, Content, State) of - {reply, Reply, NewState} -> - ok = rabbit_writer:send_command(NewState#ch.writer_pid, Reply), - NewState; - {noreply, NewState} -> - NewState; - stop -> - exit(normal) - end + try handle_method(Method, Content, State) of + {reply, Reply, NewState} -> + ok = rabbit_writer:send_command(NewState#ch.writer_pid, Reply), + NewState; + {noreply, NewState} -> + NewState; + stop -> + exit(normal) catch exit:{amqp, Error, Explanation, none} -> terminate({amqp, Error, Explanation, diff --git a/src/rabbit_error_logger_file_h.erl b/src/rabbit_error_logger_file_h.erl index 9a9220b5..183b6984 100644 --- a/src/rabbit_error_logger_file_h.erl +++ b/src/rabbit_error_logger_file_h.erl @@ -46,7 +46,7 @@ init({{File, Suffix}, []}) -> case rabbit_misc:append_file(File, Suffix) of ok -> ok; {error, Error} -> - rabbit_log:error("Failed to append contents of " ++ + rabbit_log:error("Failed to append contents of " "log file '~s' to '~s':~n~p~n", [File, [File, Suffix], Error]) end, diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index c8069e08..925c335c 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -268,8 +268,10 @@ route_internal(#exchange{name = Name}, RoutingKey) -> lookup_qpids(Queues) -> sets:fold( fun(Key, Acc) -> - [#amqqueue{pid = QPid}] = mnesia:dirty_read({amqqueue, Key}), - [QPid | Acc] + case mnesia:dirty_read({amqqueue, Key}) of + [#amqqueue{pid = QPid}] -> [QPid | Acc]; + [] -> Acc + end end, [], sets:from_list(Queues)). %% TODO: Should all of the route and binding management not be diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 973e163b..85db50d7 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -50,6 +50,7 @@ -export([dirty_read_all/1, dirty_foreach_key/2, dirty_dump_log/1]). -export([append_file/2, ensure_parent_dirs_exist/1]). -export([format_stderr/2]). +-export([start_applications/1, stop_applications/1]). -import(mnesia). -import(lists). @@ -108,6 +109,8 @@ -spec(append_file/2 :: (string(), string()) -> 'ok' | {'error', any()}). -spec(ensure_parent_dirs_exist/1 :: (string()) -> 'ok'). -spec(format_stderr/2 :: (string(), [any()]) -> 'true'). +-spec(start_applications/1 :: ([atom()]) -> 'ok'). +-spec(stop_applications/1 :: ([atom()]) -> 'ok'). -endif. @@ -398,3 +401,32 @@ format_stderr(Fmt, Args) -> Port = open_port({fd, 0, 2}, [out]), port_command(Port, io_lib:format(Fmt, Args)), port_close(Port). + +manage_applications(Iterate, Do, Undo, SkipError, ErrorTag, Apps) -> + Iterate(fun (App, Acc) -> + case Do(App) of + ok -> [App | Acc]; + {error, {SkipError, _}} -> Acc; + {error, Reason} -> + lists:foreach(Undo, Acc), + throw({error, {ErrorTag, App, Reason}}) + end + end, [], Apps), + ok. + +start_applications(Apps) -> + manage_applications(fun lists:foldl/3, + fun application:start/1, + fun application:stop/1, + already_started, + cannot_start_application, + Apps). + +stop_applications(Apps) -> + manage_applications(fun lists:foldr/3, + fun application:stop/1, + fun application:start/1, + not_started, + cannot_stop_application, + Apps). + diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl index d19c37cb..eebb38fa 100644 --- a/src/rabbit_mnesia.erl +++ b/src/rabbit_mnesia.erl @@ -243,8 +243,8 @@ init_db(ClusterNodes) -> %% NB: we cannot use rabbit_log here since %% it may not have been started yet error_logger:warning_msg( - "schema integrity check failed: ~p~n" ++ - "moving database to backup location " ++ + "schema integrity check failed: ~p~n" + "moving database to backup location " "and recreating schema from scratch~n", [Reason]), ok = move_db(), diff --git a/src/rabbit_sasl_report_file_h.erl b/src/rabbit_sasl_report_file_h.erl index 9e4c9c8a..2a365ce1 100644 --- a/src/rabbit_sasl_report_file_h.erl +++ b/src/rabbit_sasl_report_file_h.erl @@ -47,7 +47,7 @@ init({{File, Suffix}, []}) -> case rabbit_misc:append_file(File, Suffix) of ok -> ok; {error, Error} -> - rabbit_log:error("Failed to append contents of " ++ + rabbit_log:error("Failed to append contents of " "sasl log file '~s' to '~s':~n~p~n", [File, [File, Suffix], Error]) end, |