summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Klishin <michael@rabbitmq.com>2013-06-21 00:02:48 +0400
committerMichael Klishin <michael@rabbitmq.com>2013-06-21 00:02:48 +0400
commit195d184f7d0bc1bca07c5daa4f43b3d21603aa6e (patch)
treee6b5306d2cbcb5394a3c2d9f3f4098ec2e18b621
parentd984ee3a6d2f3480744c4b013e049e138267d670 (diff)
downloadrabbitmq-server-195d184f7d0bc1bca07c5daa4f43b3d21603aa6e.tar.gz
Correctly determine duplicate alarms when alarm is cleared
Also, don't bother doing anything on duplicate alarms, per review feedback.
-rw-r--r--src/rabbit_alarm.erl43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/rabbit_alarm.erl b/src/rabbit_alarm.erl
index 78098443..f3fa1962 100644
--- a/src/rabbit_alarm.erl
+++ b/src/rabbit_alarm.erl
@@ -105,14 +105,25 @@ handle_call(_Request, State) ->
handle_event({set_alarm, Alarm}, State = #alarms{alarms = Alarms}) ->
IsDuplicate = lists:member(Alarm, Alarms),
- UpdatedAlarms = lists:usort([Alarm|Alarms]),
- handle_set_alarm(Alarm, State#alarms{alarms = UpdatedAlarms}, IsDuplicate);
+ case IsDuplicate of
+ true ->
+ {ok, State};
+ false ->
+ UpdatedAlarms = lists:usort([Alarm|Alarms]),
+ handle_set_alarm(Alarm, State#alarms{alarms = UpdatedAlarms})
+ end;
handle_event({clear_alarm, Alarm}, State = #alarms{alarms = Alarms}) ->
- IsDuplicate = not lists:member(Alarm, Alarms),
- handle_clear_alarm(Alarm, State#alarms{alarms = lists:keydelete(Alarm, 1,
- Alarms)},
- IsDuplicate);
+ ExistingAlarm = lists:member(Alarm, [Res || {Res, _} <- Alarms]),
+ case ExistingAlarm of
+ true ->
+ handle_clear_alarm(Alarm,
+ State#alarms{alarms = lists:keydelete(Alarm, 1,
+ Alarms)});
+ false ->
+ {ok, State}
+
+ end;
handle_event({node_up, Node}, State) ->
%% Must do this via notify and not call to avoid possible deadlock.
@@ -223,7 +234,7 @@ internal_register(Pid, {M, F, A} = AlertMFA,
NewAlertees = dict:store(Pid, AlertMFA, Alertees),
State#alarms{alertees = NewAlertees}.
-handle_set_alarm({{resource_limit, Source, Node}, []}, State, false) ->
+handle_set_alarm({{resource_limit, Source, Node}, []}, State) ->
rabbit_log:warning(
"~s resource limit alarm set on node ~p.~n~n"
"**********************************************************~n"
@@ -231,32 +242,24 @@ handle_set_alarm({{resource_limit, Source, Node}, []}, State, false) ->
"**********************************************************~n",
[Source, Node]),
{ok, maybe_alert(fun dict_append/3, Node, Source, State)};
-handle_set_alarm({{resource_limit, Source, Node}, []}, State, true) ->
- {ok, maybe_alert(fun dict_append/3, Node, Source, State)};
-handle_set_alarm({file_descriptor_limit, []}, State, false) ->
+handle_set_alarm({file_descriptor_limit, []}, State) ->
rabbit_log:warning(
"file descriptor limit alarm set.~n~n"
"********************************************************************~n"
"*** New connections will not be accepted until this alarm clears ***~n"
"********************************************************************~n"),
{ok, State};
-handle_set_alarm({file_descriptor_limit, []}, State, true) ->
- {ok, State};
-handle_set_alarm(Alarm, State, _IsDuplicate) ->
+handle_set_alarm(Alarm, State) ->
rabbit_log:warning("alarm '~p' set~n", [Alarm]),
{ok, State}.
-handle_clear_alarm({resource_limit, Source, Node}, State, false) ->
+handle_clear_alarm({resource_limit, Source, Node}, State) ->
rabbit_log:warning("~s resource limit alarm cleared on node ~p~n",
[Source, Node]),
{ok, maybe_alert(fun dict_unappend/3, Node, Source, State)};
-handle_clear_alarm({resource_limit, Source, Node}, State, true) ->
- {ok, maybe_alert(fun dict_unappend/3, Node, Source, State)};
-handle_clear_alarm(file_descriptor_limit, State, false) ->
+handle_clear_alarm(file_descriptor_limit, State) ->
rabbit_log:warning("file descriptor limit alarm cleared~n"),
{ok, State};
-handle_clear_alarm(file_descriptor_limit, State, true) ->
- {ok, State};
-handle_clear_alarm(Alarm, State, _IsDuplicate) ->
+handle_clear_alarm(Alarm, State) ->
rabbit_log:warning("alarm '~p' cleared~n", [Alarm]),
{ok, State}.