Skip to content

Commit 91c01b6

Browse files
michaelklishinmergify[bot]
authored andcommitted
Extend #15276
(cherry picked from commit 8418f61) (cherry picked from commit 5f5b358)
1 parent ef2d7ad commit 91c01b6

2 files changed

Lines changed: 32 additions & 16 deletions

File tree

deps/rabbit/src/rabbit_db_queue.erl

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -397,23 +397,28 @@ delete(QueueName, Reason) ->
397397

398398
delete_if(QueueName, Conditions, Reason) ->
399399
rabbit_khepri:handle_fallback(
400-
#{mnesia => fun() -> delete_in_mnesia(QueueName, Reason) end,
400+
#{mnesia => fun() -> delete_in_mnesia(QueueName, Conditions, Reason) end,
401401
khepri => fun() -> delete_in_khepri(QueueName, Conditions) end
402402
}).
403403

404-
delete_in_mnesia(QueueName, Reason) ->
404+
delete_in_mnesia(QueueName, Conditions, Reason) ->
405405
rabbit_mnesia:execute_mnesia_transaction(
406406
fun () ->
407407
case {mnesia:wread({?MNESIA_TABLE, QueueName}),
408408
mnesia:wread({?MNESIA_DURABLE_TABLE, QueueName})} of
409409
{[], []} ->
410410
ok;
411-
_ ->
412-
OnlyDurable = case Reason of
413-
missing_owner -> true;
414-
_ -> false
415-
end,
416-
internal_delete_in_mnesia(QueueName, OnlyDurable, Reason)
411+
{Qs, DurableQs} ->
412+
case queue_matches_conditions(Qs ++ DurableQs, Conditions) of
413+
true ->
414+
OnlyDurable = case Reason of
415+
missing_owner -> true;
416+
_ -> false
417+
end,
418+
internal_delete_in_mnesia(QueueName, OnlyDurable, Reason);
419+
false ->
420+
ok
421+
end
417422
end
418423
end).
419424

@@ -1389,6 +1394,21 @@ clear_in_khepri() ->
13891394
%% Internal
13901395
%% --------------------------------------------------------------
13911396

1397+
queue_matches_conditions(_, []) ->
1398+
true;
1399+
queue_matches_conditions([], _Conditions) ->
1400+
false;
1401+
queue_matches_conditions([Q | _], [#if_data_matches{pattern = Pattern,
1402+
conditions = Conditions} | Rest]) ->
1403+
MatchSpec = ets:match_spec_compile([{Pattern, Conditions, [match]}]),
1404+
case ets:match_spec_run([Q], MatchSpec) of
1405+
[match] -> queue_matches_conditions([Q], Rest);
1406+
[] -> false
1407+
end;
1408+
queue_matches_conditions(_, [Condition | _]) ->
1409+
%% Unknown condition type - don't delete to be safe
1410+
error({unsupported_condition_for_mnesia, Condition}).
1411+
13921412
list_with_possible_retry_in_mnesia(Fun) ->
13931413
%% amqqueue migration:
13941414
%% The `rabbit_queue' or `rabbit_durable_queue' tables

deps/rabbit/test/rabbit_db_queue_SUITE.erl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ mnesia_tests() ->
6464
foreach_transient,
6565
delete_transient,
6666
update_in_mnesia_tx,
67-
get_durable_in_mnesia_tx
67+
get_durable_in_mnesia_tx,
68+
delete_exclusive_queue
6869
].
6970

7071
%% -------------------------------------------------------------------
@@ -326,13 +327,8 @@ delete1(_Config) ->
326327
passed.
327328

328329
delete_exclusive_queue(Config) ->
329-
case rabbit_ct_broker_helpers:configured_metadata_store(Config) of
330-
mnesia ->
331-
{skip, "this validates a bugfix only implemented for Khperi"};
332-
_ ->
333-
passed = rabbit_ct_broker_helpers:rpc(
334-
Config, 0, ?MODULE, delete_exclusive_queue1, [Config])
335-
end.
330+
passed = rabbit_ct_broker_helpers:rpc(
331+
Config, 0, ?MODULE, delete_exclusive_queue1, [Config]).
336332

337333
delete_exclusive_queue1(_Config) ->
338334
QName = rabbit_misc:r(?VHOST, queue, <<"test-exclusive-queue">>),

0 commit comments

Comments
 (0)