Skip to content

Commit a7859d4

Browse files
committed
Remove select_node logic to find node with least queue load, now just do random
1 parent 96317be commit a7859d4

File tree

1 file changed

+4
-28
lines changed

1 file changed

+4
-28
lines changed

deps/rabbit/src/rabbit_quorum_queue_periodic_membership_reconciliation.erl

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,7 @@ maybe_add_member(Q, Running, MemberNodes, TargetSize) ->
163163
true ->
164164
%% In the future, sort the list of new nodes based on load,
165165
%% availability zones etc
166-
QueueCount = rabbit_amqqueue:count(),
167-
QueueCountStartRandom = application:get_env(rabbit, queue_count_start_random_selection,
168-
?QUEUE_COUNT_START_RANDOM_SELECTION),
169-
Node = select_node(New, QueueCount, QueueCountStartRandom),
166+
Node = select_node(New),
170167
QName = amqqueue:get_name(Q),
171168
case rabbit_quorum_queue:add_member(Q, Node) of
172169
ok ->
@@ -241,28 +238,7 @@ update_result(Result, noop) ->
241238
update_result(Result, Result) ->
242239
Result.
243240

244-
select_node([Node], _QueueCount, _QueueCountStartRandom) ->
241+
select_node([Node]) ->
245242
Node;
246-
select_node(Nodes, QueueCount, QueueCountStartRandom)
247-
when QueueCount >= QueueCountStartRandom ->
248-
lists:nth(rand:uniform(length(Nodes)), Nodes);
249-
select_node(Nodes, _QueueCount, _QueueCountStartRandom) ->
250-
Counters0 = maps:from_list([{N, 0} || N <- Nodes]),
251-
Queues = rabbit_amqqueue:list_by_type(rabbit_quorum_queue),
252-
Counters = lists:foldl(fun(Q, Acc) ->
253-
#{nodes := MNodes} = amqqueue:get_type_state(Q),
254-
lists:foldl(fun(N, A)
255-
when is_map_key(N, A) ->
256-
maps:update_with(N, fun(C) -> C+1 end, A);
257-
(_, A) ->
258-
A
259-
end, Acc, MNodes)
260-
end, Counters0, Queues),
261-
L0 = maps:to_list(Counters),
262-
%% Maybe cache this result for a few seconds, to
263-
%% not run this check for each queue?
264-
L1 = lists:sort(fun({_N0, C0}, {_N1, C1}) ->
265-
C0 =< C1
266-
end, L0),
267-
{Node, _} = hd(L1),
268-
Node.
243+
select_node(Nodes) ->
244+
lists:nth(rand:uniform(length(Nodes)), Nodes).

0 commit comments

Comments
 (0)