diff options
author | Alexandru Scvortov <alexandru@rabbitmq.com> | 2011-01-31 10:59:45 +0000 |
---|---|---|
committer | Alexandru Scvortov <alexandru@rabbitmq.com> | 2011-01-31 10:59:45 +0000 |
commit | fb7cd81fef32fbb0e18fa6e8ec6bff0c5d03b880 (patch) | |
tree | a5b8aeb3929d58da314620629f655003a9a32de6 | |
parent | 9f354ec05ce5e37a214e4d1caca1d003bc964bda (diff) | |
download | rabbitmq-server-fb7cd81fef32fbb0e18fa6e8ec6bff0c5d03b880.tar.gz |
monitor rabbits on clustered nodes
When a rabbit starts, it,
* informs every other running node in the cluster that it has
started, and
* registers every other running node in the cluster as running.
This should handle every possible case of nodes joining clusters,
since every join should be followed by that node starting.
We can't just monitor 'rabbit' on node ups, since those come in when
mnesia joins the cluster. The rabbit process starts up a bit later.
-rw-r--r-- | src/rabbit.erl | 11 | ||||
-rw-r--r-- | src/rabbit_node_monitor.erl | 13 |
2 files changed, 18 insertions, 6 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl index 9a938d10..92bc8802 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -230,7 +230,16 @@ start(normal, []) -> print_banner(), [ok = run_boot_step(Step) || Step <- boot_steps()], io:format("~nbroker running~n"), - + io:format("informing other clustered brokers: ~p~n", + [rabbit_mnesia:running_clustered_nodes()]), + %% notify other rabbits of this rabbit + [ rpc:call(Node, rabbit_node_monitor, rabbit_running_on, [node()]) + || Node <- rabbit_mnesia:running_clustered_nodes(), + Node =/= node() ], + %% register other active rabbits with this rabbit + [ rabbit_node_monitor:rabbit_running_on(Node) + || Node <- rabbit_mnesia:running_clustered_nodes(), + Node =/= node() ], {ok, SupPid}; Error -> Error diff --git a/src/rabbit_node_monitor.erl b/src/rabbit_node_monitor.erl index bce5ec12..c36a1dfb 100644 --- a/src/rabbit_node_monitor.erl +++ b/src/rabbit_node_monitor.erl @@ -22,6 +22,7 @@ -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). +-export([rabbit_running_on/1]). -define(SERVER, ?MODULE). @@ -30,6 +31,9 @@ start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). +rabbit_running_on(Node) -> + gen_server:cast(rabbit_node_monitor, {rabbit_running_on, Node}). + %%-------------------------------------------------------------------- init([]) -> @@ -39,14 +43,14 @@ init([]) -> handle_call(_Request, _From, State) -> {noreply, State}. -handle_cast(_Msg, State) -> - {noreply, State}. - -handle_info({nodeup, Node}, State) -> +handle_cast({rabbit_running_on, Node}, State) -> rabbit_log:info("node ~p up", [Node]), erlang:monitor(process, {rabbit, Node}), io:format("monitored 'rabbit' on ~p~n", [Node]), {noreply, State}; +handle_cast(_Msg, State) -> + {noreply, State}. + handle_info({nodedown, Node}, State) -> rabbit_log:info("node ~p down", [Node]), %% TODO: This may turn out to be a performance hog when there are @@ -68,4 +72,3 @@ code_change(_OldVsn, State, _Extra) -> {ok, State}. %%-------------------------------------------------------------------- - |