Skip to content

Commit 802a9c9

Browse files
Merge pull request #3639 from rabbitmq/mergify/bp/v3.9.x/pr-3635
Introduce a target cluster size hint setting (backport #3635)
2 parents 3262602 + 3fe9775 commit 802a9c9

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

deps/rabbit/priv/schema/rabbit.schema

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,18 @@ end}.
11241124
{validators, ["non_zero_positive_integer"]}
11251125
]}.
11261126

1127+
1128+
%% Target cluster size hint may be used by certain core features or plugins to perform
1129+
%% actions that should only be performed when a certain number of nodes (or a quorum of a certain number)
1130+
%% has already joined (started).
1131+
%%
1132+
1133+
{mapping, "cluster_formation.target_cluster_size_hint", "rabbit.cluster_formation.target_cluster_size_hint", [
1134+
{datatype, integer},
1135+
{validators, ["non_zero_positive_integer"]}
1136+
]}.
1137+
1138+
11271139
%% Classic config-driven peer discovery backend.
11281140
%%
11291141
%% Make clustering happen *automatically* at startup - only applied

deps/rabbit/src/rabbit_nodes.erl

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
await_running_count/2, is_single_node_cluster/0,
1515
boot/0]).
1616
-export([persistent_cluster_id/0, seed_internal_cluster_id/0, seed_user_provided_cluster_name/0]).
17-
-export([all/0, all_running_with_hashes/0]).
17+
-export([all/0, all_running_with_hashes/0, target_cluster_size_hint/0, reached_target_cluster_size/0]).
1818
-export([lock_id/1, lock_retries/0]).
1919

2020
-include_lib("kernel/include/inet.hrl").
@@ -30,6 +30,8 @@
3030
% 80 corresponds to a timeout of ca 300 seconds.
3131
-define(DEFAULT_LOCK_RETRIES, 80).
3232

33+
-define(DEFAULT_TARGET_CLUSTER_SIZE, 1).
34+
3335
%%----------------------------------------------------------------------------
3436
%% API
3537
%%----------------------------------------------------------------------------
@@ -173,15 +175,32 @@ await_running_count_with_retries(TargetCount, Retries) ->
173175
all_running_with_hashes() ->
174176
maps:from_list([{erlang:phash2(Node), Node} || Node <- all_running()]).
175177

178+
-spec target_cluster_size_hint() -> non_neg_integer().
179+
target_cluster_size_hint() ->
180+
cluster_formation_key_or_default(target_cluster_size_hint, ?DEFAULT_TARGET_CLUSTER_SIZE).
181+
182+
-spec reached_target_cluster_size() -> boolean().
183+
reached_target_cluster_size() ->
184+
running_count() >= target_cluster_size_hint().
185+
186+
176187
-spec lock_id(Node :: node()) -> {ResourceId :: string(), LockRequesterId :: node()}.
177188
lock_id(Node) ->
178189
{cookie_hash(), Node}.
179190

180191
-spec lock_retries() -> integer().
181192
lock_retries() ->
182-
case application:get_env(rabbit, cluster_formation) of
183-
{ok, PropList} ->
184-
proplists:get_value(internal_lock_retries, PropList, ?DEFAULT_LOCK_RETRIES);
185-
undefined ->
186-
?DEFAULT_LOCK_RETRIES
187-
end.
193+
cluster_formation_key_or_default(internal_lock_retries, ?DEFAULT_LOCK_RETRIES).
194+
195+
196+
%%
197+
%% Implementation
198+
%%
199+
200+
cluster_formation_key_or_default(Key, Default) ->
201+
case application:get_env(rabbit, cluster_formation) of
202+
{ok, PropList} ->
203+
proplists:get_value(Key, PropList, Default);
204+
undefined ->
205+
Default
206+
end.

deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ cluster_formation.dns.hostname = discovery.eng.example.local",
139139
[]},
140140
{cluster_formation_ram_ignored,
141141
"cluster_formation.node_type = ram",[],[]},
142+
{cluster_formation_target_cluster_size_hint,
143+
"cluster_formation.target_cluster_size_hint = 3",
144+
[{rabbit, [
145+
{cluster_formation, [
146+
{target_cluster_size_hint, 3}
147+
]}
148+
]}],
149+
[]},
150+
142151
{tcp_listen_options,
143152
"tcp_listen_options.backlog = 128
144153
tcp_listen_options.nodelay = true

0 commit comments

Comments
 (0)