From 00958b5c4ce467c3af1a48af3b95014e1289e977 Mon Sep 17 00:00:00 2001 From: Simon MacMullen Date: Fri, 1 Mar 2013 17:49:24 +0000 Subject: [PATCH] Delete all appropriate connection / channel records when a node goes down. --- deps/rabbitmq_management/src/rabbit_mgmt_db.erl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/deps/rabbitmq_management/src/rabbit_mgmt_db.erl b/deps/rabbitmq_management/src/rabbit_mgmt_db.erl index b7ebf35ee8..69ff8ad5fc 100644 --- a/deps/rabbitmq_management/src/rabbit_mgmt_db.erl +++ b/deps/rabbitmq_management/src/rabbit_mgmt_db.erl @@ -215,6 +215,7 @@ init([]) -> %% that the management plugin work. process_flag(priority, high), {ok, Interval} = application:get_env(rabbit, collect_statistics_interval), + rabbit_node_monitor:subscribe(self()), rabbit_log:info("Statistics database started.~n"), {ok, #state{interval = Interval, tables = orddict:from_list( @@ -319,6 +320,13 @@ handle_cast({event, Event}, State) -> handle_cast(_Request, State) -> noreply(State). +handle_info({node_down, Node}, State = #state{tables = Tables}) -> + Conns = created_events(connection_stats, Tables), + Chs = created_events(channel_stats, Tables), + delete_all_from_node(connection_closed, Node, Conns, State), + delete_all_from_node(channel_closed, Node, Chs, State), + noreply(State); + handle_info(_Info, State) -> noreply(State). @@ -343,6 +351,12 @@ handle_pre_hibernate(State) -> %%---------------------------------------------------------------------------- +delete_all_from_node(Type, Node, Items, State) -> + [case node(Pid) of + Node -> handle_event(#event{type = Type, props = [{pid, Pid}]}, State); + _ -> ok + end || Item <- Items, Pid <- [pget(pid, Item)]]. + handle_event(#event{type = queue_stats, props = Stats, timestamp = Timestamp}, State) -> handle_stats(queue_stats, Stats, Timestamp,