diff options
author | Matthias Radestock <matthias@rabbitmq.com> | 2012-09-25 14:19:55 +0100 |
---|---|---|
committer | Matthias Radestock <matthias@rabbitmq.com> | 2012-09-25 14:19:55 +0100 |
commit | 8423dd2fcde33deabe887988f3d70c68074ed279 (patch) | |
tree | 01c2fc5f045a70061203fa44c4fcf05ab86db7a2 | |
parent | 6dd18fb33de46427e1f3f0604965a1e1c6f78543 (diff) | |
download | rabbitmq-server-8423dd2fcde33deabe887988f3d70c68074ed279.tar.gz |
track monitors explicitly
-rw-r--r-- | src/rabbit_node_monitor.erl | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/rabbit_node_monitor.erl b/src/rabbit_node_monitor.erl index aaee583f..026aa362 100644 --- a/src/rabbit_node_monitor.erl +++ b/src/rabbit_node_monitor.erl @@ -171,7 +171,7 @@ notify_left_cluster(Node) -> %% gen_server callbacks %%---------------------------------------------------------------------------- -init([]) -> {ok, no_state}. +init([]) -> {ok, pmon:new()}. handle_call(_Request, _From, State) -> {noreply, State}. @@ -179,9 +179,9 @@ handle_call(_Request, _From, State) -> %% Note: when updating the status file, we can't simply write the %% mnesia information since the message can (and will) overtake the %% mnesia propagation. -handle_cast({node_up, Node, NodeType}, State) -> - case is_already_monitored({rabbit, Node}) of - true -> {noreply, State}; +handle_cast({node_up, Node, NodeType}, Monitors) -> + case pmon:is_monitored({rabbit, Node}, Monitors) of + true -> {noreply, Monitors}; false -> rabbit_log:info("rabbit on node ~p up~n", [Node]), {AllNodes, DiscNodes, RunningNodes} = read_cluster_status(), write_cluster_status({add_node(Node, AllNodes), @@ -190,9 +190,8 @@ handle_cast({node_up, Node, NodeType}, State) -> ram -> DiscNodes end, add_node(Node, RunningNodes)}), - erlang:monitor(process, {rabbit, Node}), ok = handle_live_rabbit(Node), - {noreply, State} + {noreply, pmon:monitor({rabbit, Node}, Monitors)} end; handle_cast({joined_cluster, Node, NodeType}, State) -> {AllNodes, DiscNodes, RunningNodes} = read_cluster_status(), @@ -211,12 +210,12 @@ handle_cast({left_cluster, Node}, State) -> handle_cast(_Msg, State) -> {noreply, State}. -handle_info({'DOWN', _MRef, process, {rabbit, Node}, _Reason}, State) -> +handle_info({'DOWN', _MRef, process, {rabbit, Node}, _Reason}, Monitors) -> rabbit_log:info("rabbit on node ~p down~n", [Node]), {AllNodes, DiscNodes, RunningNodes} = read_cluster_status(), write_cluster_status({AllNodes, DiscNodes, del_node(Node, RunningNodes)}), ok = handle_dead_rabbit(Node), - {noreply, State}; + {noreply, pmon:erase({rabbit, Node}, Monitors)}; handle_info(_Info, State) -> {noreply, State}. @@ -254,12 +253,6 @@ try_read_file(FileName) -> {error, E} -> throw({error, {cannot_read_file, FileName, E}}) end. -is_already_monitored(Item) -> - {monitors, Monitors} = process_info(self(), monitors), - lists:any(fun ({_, Item1}) when Item =:= Item1 -> true; - (_) -> false - end, Monitors). - legacy_cluster_nodes(Nodes) -> %% We get all the info that we can, including the nodes from %% mnesia, which will be there if the node is a disc node (empty |