Skip to content

Fix rabbit_priority_queue:update_rates bug #11814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions deps/rabbit/src/rabbit_priority_queue.erl
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ depth(#passthrough{bq = BQ, bqs = BQS}) ->
BQ:depth(BQS).

update_rates(State = #state{bq = BQ}) ->
fold_min2(fun (_P, BQSN) -> BQ:update_rates(BQSN) end, State);
foreach1(fun (_P, BQSN) -> BQ:update_rates(BQSN) end, State);
update_rates(State = #passthrough{bq = BQ, bqs = BQS}) ->
?passthrough1(update_rates(BQS)).

Expand Down Expand Up @@ -490,13 +490,6 @@ fold_add2(Fun, State) ->
{add_maybe_infinity(Res, Acc), BQSN1}
end, 0, State).

%% Fold over results assuming results are numbers and we want the minimum
fold_min2(Fun, State) ->
fold2(fun (P, BQSN, Acc) ->
{Res, BQSN1} = Fun(P, BQSN),
{erlang:min(Res, Acc), BQSN1}
end, infinity, State).

%% Fold over results assuming results are lists and we want to append
%% them, and also that we have some AckTags we want to pass in to each
%% invocation.
Expand Down
31 changes: 30 additions & 1 deletion deps/rabbit/test/priority_queue_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ groups() ->
invoke,
gen_server2_stats,
negative_max_priorities,
max_priorities_above_hard_limit
max_priorities_above_hard_limit,
update_rates
]}
].

Expand Down Expand Up @@ -473,6 +474,24 @@ unknown_info_key(Config) ->
rabbit_ct_client_helpers:close_connection(Conn),
passed.

update_rates(Config) ->
Node = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
{Conn, Ch} = rabbit_ct_client_helpers:open_connection_and_channel(Config, 0),
Q = <<"update_rates-queue">>,
declare(Ch, Q, [{<<"x-max-priority">>, byte, 3}]),
QPid = queue_pid(Config, Node, rabbit_misc:r(<<"/">>, queue, Q)),
try
publish1(Ch, Q, 1),
QPid ! update_rates,
State = get_state(Config, Q),
?assertEqual(live, State),
delete(Ch, Q)
after
rabbit_ct_client_helpers:close_channel(Ch),
rabbit_ct_client_helpers:close_connection(Conn),
passed
end.

%%----------------------------------------------------------------------------

declare(Ch, Q, Args) when is_list(Args) ->
Expand Down Expand Up @@ -590,4 +609,14 @@ info(Config, Q, InfoKeys) ->
Config, Nodename,
rabbit_classic_queue, info, [Amq, InfoKeys]),
{ok, Info}.

get_state(Config, Q) ->
Nodename = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
{ok, Amq} = rabbit_ct_broker_helpers:rpc(
Config, Nodename,
rabbit_amqqueue, lookup, [rabbit_misc:r(<<"/">>, queue, Q)]),
rabbit_ct_broker_helpers:rpc(
Config, Nodename,
amqqueue, get_state, [Amq]).

%%----------------------------------------------------------------------------
Loading