Skip to content

Commit f74c13f

Browse files
Merge branch 'mk-backport-rabbitmq-server-13194' into v4.0.x
This is a manual backport of #13201. References #13194.
2 parents b0ccce1 + 6076d35 commit f74c13f

File tree

3 files changed

+71
-16
lines changed

3 files changed

+71
-16
lines changed

deps/rabbit/priv/schema/rabbit.schema

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,13 @@ fun(Conf) ->
13701370
end
13711371
end}.
13721372

1373+
%% Register node during cluster formation when backend supports registration.
1374+
%%
1375+
1376+
{mapping, "cluster_formation.registration.enabled", "rabbit.cluster_formation.perform_registration", [
1377+
{datatype, {enum, [true, false]}}
1378+
]}.
1379+
13731380
%% Cluster formation: lock acquisition retries as passed to https://erlang.org/doc/man/global.html#set_lock-3
13741381
%%
13751382
%% Currently used in classic, k8s, and aws peer discovery backends.

deps/rabbit/src/rabbit_peer_discovery.erl

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

49+
%% Register node by default (with the backends that support registration)
50+
-define(PERFORM_REGISTRATION_BY_DEFAULT, true).
51+
4952
%% default node prefix to attach to discovered hostnames
5053
-define(DEFAULT_PREFIX, "rabbit").
5154

@@ -82,6 +85,16 @@ node_type() ->
8285
?DEFAULT_NODE_TYPE
8386
end.
8487

88+
-spec should_perform_registration() -> true | false.
89+
90+
should_perform_registration() ->
91+
case application:get_env(rabbit, cluster_formation) of
92+
{ok, Proplist} ->
93+
proplists:get_value(perform_registration, Proplist, ?PERFORM_REGISTRATION_BY_DEFAULT);
94+
undefined ->
95+
?PERFORM_REGISTRATION_BY_DEFAULT
96+
end.
97+
8598
-spec lock_acquisition_failure_mode() -> ignore | fail.
8699

87100
lock_acquisition_failure_mode() ->
@@ -968,35 +981,51 @@ error_description({invalid_cluster_node_type, BadType}) ->
968981
-spec maybe_register() -> ok.
969982

970983
maybe_register() ->
971-
Backend = persistent_term:get(?PT_PEER_DISC_BACKEND, backend()),
972-
case Backend:supports_registration() of
984+
case should_perform_registration() of
973985
true ->
974-
?LOG_DEBUG(
975-
"Peer discovery: registering this node",
976-
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
977-
register(Backend),
978-
_ = Backend:post_registration(),
979-
ok;
986+
Backend = persistent_term:get(?PT_PEER_DISC_BACKEND, backend()),
987+
case Backend:supports_registration() of
988+
true ->
989+
?LOG_DEBUG(
990+
"Peer discovery: registering this node",
991+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
992+
register(Backend),
993+
_ = Backend:post_registration(),
994+
ok;
995+
false ->
996+
?LOG_DEBUG(
997+
"Peer discovery: registration is not supported, skipping it",
998+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
999+
ok
1000+
end;
9801001
false ->
9811002
?LOG_DEBUG(
982-
"Peer discovery: registration unsupported, skipping register",
1003+
"Peer discovery: registration is disabled via configuration, skipping it",
9831004
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
9841005
ok
9851006
end.
9861007

9871008
-spec maybe_unregister() -> ok.
9881009

9891010
maybe_unregister() ->
990-
Backend = persistent_term:get(?PT_PEER_DISC_BACKEND),
991-
case Backend:supports_registration() of
1011+
case should_perform_registration() of
9921012
true ->
993-
?LOG_DEBUG(
994-
"Peer discovery: unregistering this node",
995-
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
996-
unregister(Backend);
1013+
Backend = persistent_term:get(?PT_PEER_DISC_BACKEND),
1014+
case Backend:supports_registration() of
1015+
true ->
1016+
?LOG_DEBUG(
1017+
"Peer discovery: unregistering this node",
1018+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
1019+
unregister(Backend);
1020+
false ->
1021+
?LOG_DEBUG(
1022+
"Peer discovery: registration is not supported, skipping unregistration",
1023+
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
1024+
ok
1025+
end;
9971026
false ->
9981027
?LOG_DEBUG(
999-
"Peer discovery: registration unsupported, skipping unregister",
1028+
"Peer discovery: registration is disabled via configuration, skipping unregistration",
10001029
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
10011030
ok
10021031
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_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)