Skip to content

Commit f16bf5c

Browse files
frederikboschmichaelklishin
authored andcommitted
add option to disable registration of node during cluster formation
1 parent 3e9f2b5 commit f16bf5c

File tree

2 files changed

+52
-16
lines changed

2 files changed

+52
-16
lines changed

deps/rabbit/priv/schema/rabbit.schema

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,13 @@ end}.
13531353
{datatype, {enum, [disc, disk, ram]}}
13541354
]}.
13551355

1356+
%% Register node during cluster formation.
1357+
%%
1358+
1359+
{mapping, "cluster_formation.registration", "rabbit.cluster_formation.register", [
1360+
{datatype, {enum, [true, false]}}
1361+
]}.
1362+
13561363
{translation, "rabbit.cluster_formation.node_type",
13571364
fun(Conf) ->
13581365
%% if peer discovery backend isn't configured, don't generate

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
50+
-define(DEFAULT_REGISTRATION, 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 registration() -> true | false.
89+
90+
registration() ->
91+
case application:get_env(rabbit, cluster_formation) of
92+
{ok, Proplist} ->
93+
proplists:get_value(registration, Proplist, ?DEFAULT_REGISTRATION);
94+
undefined ->
95+
?DEFAULT_REGISTRATION
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 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 unsupported, skipping register",
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 disabled, skipping register",
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 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 unsupported, skipping unregister",
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 disabled, skipping unregister",
10001029
#{domain => ?RMQLOG_DOMAIN_PEER_DISC}),
10011030
ok
10021031
end.

0 commit comments

Comments
 (0)