diff options
author | Michael Klishin <mklishin@pivotal.io> | 2017-03-22 02:42:46 +0300 |
---|---|---|
committer | Michael Klishin <mklishin@pivotal.io> | 2017-03-22 02:42:46 +0300 |
commit | c0ad88e6c2ad34a216733eb9f766911ff9669f80 (patch) | |
tree | 176bf4dfc0412b20d037d8582de5867598e5bb48 | |
parent | 5565bb9320656533ad1fea78a8c6d2ff57b4a3e1 (diff) | |
download | rabbitmq-server-git-c0ad88e6c2ad34a216733eb9f766911ff9669f80.tar.gz |
Register with peer discovery backend on start if the backend supports it
This introduces a new function to the peer discovery interface.
The idea is to let backends indicate if they support registration.
The goal is not to avoid calling the function, since Erlang
behaviours require all functions to be implemented anyway.
What we are trying to avoid with this is extra log entries
that say "[un]registering with ..." as they can be confusing
e.g. in single node installations.
References #1143.
-rw-r--r-- | src/rabbit.erl | 8 | ||||
-rw-r--r-- | src/rabbit_peer_discovery.erl | 42 | ||||
-rw-r--r-- | src/rabbit_peer_discovery_classic_config.erl | 7 | ||||
-rw-r--r-- | src/rabbit_peer_discovery_dns.erl | 9 |
4 files changed, 60 insertions, 6 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl index be75321714..f510985deb 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -327,7 +327,9 @@ broker_start() -> ToBeLoaded = Plugins ++ ?APPS, start_apps(ToBeLoaded), maybe_sd_notify(), - ok = log_broker_started(rabbit_plugins:strictly_plugins(rabbit_plugins:active())). + ok = log_broker_started(rabbit_plugins:strictly_plugins(rabbit_plugins:active())), + rabbit_peer_discovery:maybe_register(), + ok. %% Try to send systemd ready notification if it makes sense in the %% current environment. standard_error is used intentionally in all @@ -472,7 +474,7 @@ stop() -> rabbit_log:info("RabbitMQ is asked to stop...~n", []), Apps = ?APPS ++ rabbit_plugins:active(), stop_apps(app_utils:app_dependency_order(Apps, true)), - rabbit_peer_discovery:unregister(), + rabbit_peer_discovery:maybe_unregister(), rabbit_log:info("Successfully stopped RabbitMQ and its dependencies~n", []). stop_and_halt() -> @@ -755,7 +757,7 @@ start(normal, []) -> end. prep_stop(State) -> - rabbit_peer_discovery:unregister(), + rabbit_peer_discovery:maybe_unregister(), State. stop(_State) -> diff --git a/src/rabbit_peer_discovery.erl b/src/rabbit_peer_discovery.erl index a93c63ac05..2b6701210a 100644 --- a/src/rabbit_peer_discovery.erl +++ b/src/rabbit_peer_discovery.erl @@ -22,7 +22,7 @@ -export([discover_cluster_nodes/0, backend/0, node_type/0, normalize/1, format_discovered_nodes/1, log_configured_backend/0, - unregister/0]). + register/0, unregister/0, maybe_register/0, maybe_unregister/0]). -export([append_node_prefix/1, node_prefix/0]). -define(DEFAULT_BACKEND, rabbit_peer_discovery_classic_config). @@ -73,6 +73,46 @@ discover_cluster_nodes() -> normalize(Backend:list_nodes()). +-spec maybe_register() -> ok. + +maybe_register() -> + Backend = backend(), + case Backend:supports_registration() of + true -> + register(); + false -> + rabbit_log:info("Peer discovery backend ~s does not support registration, skipping registration.", [Backend]), + ok + end. + + +-spec maybe_unregister() -> ok. + +maybe_unregister() -> + Backend = backend(), + case Backend:supports_registration() of + true -> + unregister(); + false -> + rabbit_log:info("Peer discovery backend ~s does not support registration, skipping unregistration.", [Backend]), + ok + end. + + +-spec register() -> ok. + +register() -> + Backend = backend(), + rabbit_log:info("Will register with peer discovery backend ~s", [Backend]), + case Backend:register() of + ok -> ok; + {error, Error} -> + rabbit_log:error("Failed to register with peer discovery backend ~s: ~p", + [Backend, Error]), + ok + end. + + -spec unregister() -> ok. unregister() -> diff --git a/src/rabbit_peer_discovery_classic_config.erl b/src/rabbit_peer_discovery_classic_config.erl index a3d3d50617..d27997240a 100644 --- a/src/rabbit_peer_discovery_classic_config.erl +++ b/src/rabbit_peer_discovery_classic_config.erl @@ -19,7 +19,7 @@ -include("rabbit.hrl"). --export([list_nodes/0, register/0, unregister/0]). +-export([list_nodes/0, supports_registration/0, register/0, unregister/0]). %% %% API @@ -34,6 +34,11 @@ list_nodes() -> undefined -> {[], disc} end. +-spec supports_registration() -> boolean(). + +supports_registration() -> + false. + -spec register() -> ok. register() -> diff --git a/src/rabbit_peer_discovery_dns.erl b/src/rabbit_peer_discovery_dns.erl index 05102bebab..6082f823b6 100644 --- a/src/rabbit_peer_discovery_dns.erl +++ b/src/rabbit_peer_discovery_dns.erl @@ -19,7 +19,7 @@ -include("rabbit.hrl"). --export([list_nodes/0, register/0, unregister/0]). +-export([list_nodes/0, supports_registration/0, register/0, unregister/0]). %% for tests -export([discover_nodes/2, discover_hostnames/2]). @@ -48,6 +48,13 @@ list_nodes() -> end end. + +-spec supports_registration() -> boolean(). + +supports_registration() -> + false. + + -spec register() -> ok. register() -> |