Skip to content

Commit 225257d

Browse files
Make it possible to opt out of peer discovery registration
for the backends that support it in the first place. When forming a cluster, registration of the node joining the cluster might be left to (container) orchestration tools like Nomad or Kubernetes. This PR add a new configuration option, 'cluster_formation.registration.enable', which defaults to true. When set to false node registration will be skipped. There is at least one important advantage using a tool such as Nomad (plus Consul) over the application (RabbitMQ) doing the registration. When the application is not stopped gracefully for any reason, e.g. its OOM killed, it cannot deregister the service/node. This leaves behind an unlinked service entry in the registry. This problem is fundamentally avoided by allowing Nomad (or similar tools) to register the node'service. See #11233 #11045 for prior discussions. Co-authored-by: Frederik Bosch <[email protected]> (cherry picked from commit 269685d)
1 parent 347679d commit 225257d

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

deps/rabbit/priv/schema/rabbit.schema

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,7 @@ end}.
13731373
%% Register node during cluster formation when backend supports registration.
13741374
%%
13751375

1376-
{mapping, "cluster_formation.registration", "rabbit.cluster_formation.register", [
1376+
{mapping, "cluster_formation.registration.enabled", "rabbit.cluster_formation.perform_registration", [
13771377
{datatype, {enum, [true, false]}}
13781378
]}.
13791379

deps/rabbit/src/rabbit_peer_discovery.erl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
%% a new cluster as a virgin node
4747
-define(DEFAULT_NODE_TYPE, disc).
4848

49-
%% register node by default
50-
-define(DEFAULT_REGISTRATION, true).
49+
%% Register node by default (with the backends that support registration)
50+
-define(PERFORM_REGISTRATION_BY_DEFAULT, true).
5151

5252
%% default node prefix to attach to discovered hostnames
5353
-define(DEFAULT_PREFIX, "rabbit").
@@ -85,14 +85,14 @@ node_type() ->
8585
?DEFAULT_NODE_TYPE
8686
end.
8787

88-
-spec registration() -> true | false.
88+
-spec should_perform_registration() -> true | false.
8989

90-
registration() ->
90+
should_perform_registration() ->
9191
case application:get_env(rabbit, cluster_formation) of
9292
{ok, Proplist} ->
93-
proplists:get_value(registration, Proplist, ?DEFAULT_REGISTRATION);
93+
proplists:get_value(perform_registration, Proplist, ?PERFORM_REGISTRATION_BY_DEFAULT);
9494
undefined ->
95-
?DEFAULT_REGISTRATION
95+
?PERFORM_REGISTRATION_BY_DEFAULT
9696
end.
9797

9898
-spec lock_acquisition_failure_mode() -> ignore | fail.
@@ -981,7 +981,7 @@ error_description({invalid_cluster_node_type, BadType}) ->
981981
-spec maybe_register() -> ok.
982982

983983
maybe_register() ->
984-
case registration() of
984+
case should_perform_registration() of
985985
true ->
986986
Backend = persistent_term:get(?PT_PEER_DISC_BACKEND, backend()),
987987
case Backend:supports_registration() of
@@ -994,21 +994,21 @@ maybe_register() ->
994994
ok;
995995
false ->
996996
?LOG_DEBUG(
997-
"Peer discovery: registration unsupported, skipping register",
997+
"Peer discovery: registration is not supported, skipping it",
998998
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
999999
ok
1000-
end.
1000+
end;
10011001
false ->
10021002
?LOG_DEBUG(
1003-
"Peer discovery: registration disabled, skipping register",
1003+
"Peer discovery: registration is disabled via configuration, skipping it",
10041004
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
10051005
ok
10061006
end.
10071007

10081008
-spec maybe_unregister() -> ok.
10091009

10101010
maybe_unregister() ->
1011-
case registration() of
1011+
case should_perform_registration() of
10121012
true ->
10131013
Backend = persistent_term:get(?PT_PEER_DISC_BACKEND),
10141014
case Backend:supports_registration() of
@@ -1019,13 +1019,13 @@ maybe_unregister() ->
10191019
unregister(Backend);
10201020
false ->
10211021
?LOG_DEBUG(
1022-
"Peer discovery: registration unsupported, skipping unregister",
1022+
"Peer discovery: registration is not supported, skipping unregistration",
10231023
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
10241024
ok
1025-
end.
1025+
end;
10261026
false ->
10271027
?LOG_DEBUG(
1028-
"Peer discovery: registration disabled, skipping unregister",
1028+
"Peer discovery: registration is disabled via configuration, skipping unregistration",
10291029
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
10301030
ok
10311031
end.

deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,25 @@ cluster_formation.dns.hostname = discovery.eng.example.local",
310310
]}],
311311
[]},
312312

313+
%% registration is enabled by default for the backends that support it
314+
{cluster_formation_explicitly_enable_of_registration,
315+
"cluster_formation.registration.enabled = true",
316+
[{rabbit,
317+
[{cluster_formation, [
318+
{perform_registration, true}
319+
]}]
320+
}],
321+
[]},
322+
323+
{cluster_formation_opt_out_of_registration,
324+
"cluster_formation.registration.enabled = false",
325+
[{rabbit,
326+
[{cluster_formation, [
327+
{perform_registration, false}
328+
]}]
329+
}],
330+
[]},
331+
313332
{tcp_listen_options,
314333
"tcp_listen_options.backlog = 128
315334
tcp_listen_options.nodelay = true

0 commit comments

Comments
 (0)