Skip to content

Commit 7e6299c

Browse files
Extend #15276
1 parent e763f80 commit 7e6299c

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
@@ -399,23 +399,28 @@ delete(QueueName, Reason) ->
399399

400400
delete_if(QueueName, Conditions, Reason) ->
401401
rabbit_khepri:handle_fallback(
402-
#{mnesia => fun() -> delete_in_mnesia(QueueName, Reason) end,
402+
#{mnesia => fun() -> delete_in_mnesia(QueueName, Conditions, Reason) end,
403403
khepri => fun() -> delete_in_khepri(QueueName, Conditions) end
404404
}).
405405

406-
delete_in_mnesia(QueueName, Reason) ->
406+
delete_in_mnesia(QueueName, Conditions, Reason) ->
407407
rabbit_mnesia:execute_mnesia_transaction(
408408
fun () ->
409409
case {mnesia:wread({?MNESIA_TABLE, QueueName}),
410410
mnesia:wread({?MNESIA_DURABLE_TABLE, QueueName})} of
411411
{[], []} ->
412412
ok;
413-
_ ->
414-
OnlyDurable = case Reason of
415-
missing_owner -> true;
416-
_ -> false
417-
end,
418-
internal_delete_in_mnesia(QueueName, OnlyDurable, Reason)
413+
{Qs, DurableQs} ->
414+
case queue_matches_conditions(Qs ++ DurableQs, Conditions) of
415+
true ->
416+
OnlyDurable = case Reason of
417+
missing_owner -> true;
418+
_ -> false
419+
end,
420+
internal_delete_in_mnesia(QueueName, OnlyDurable, Reason);
421+
false ->
422+
ok
423+
end
419424
end
420425
end).
421426

@@ -1457,6 +1462,21 @@ clear_in_khepri() ->
14571462
%% Internal
14581463
%% --------------------------------------------------------------
14591464

1465+
queue_matches_conditions(_, []) ->
1466+
true;
1467+
queue_matches_conditions([], _Conditions) ->
1468+
false;
1469+
queue_matches_conditions([Q | _], [#if_data_matches{pattern = Pattern,
1470+
conditions = Conditions} | Rest]) ->
1471+
MatchSpec = ets:match_spec_compile([{Pattern, Conditions, [match]}]),
1472+
case ets:match_spec_run([Q], MatchSpec) of
1473+
[match] -> queue_matches_conditions([Q], Rest);
1474+
[] -> false
1475+
end;
1476+
queue_matches_conditions(_, [Condition | _]) ->
1477+
%% Unknown condition type - don't delete to be safe
1478+
error({unsupported_condition_for_mnesia, Condition}).
1479+
14601480
list_with_possible_retry_in_mnesia(Fun) ->
14611481
%% amqqueue migration:
14621482
%% 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
%% -------------------------------------------------------------------
@@ -330,13 +331,8 @@ delete1(_Config) ->
330331
passed.
331332

332333
delete_exclusive_queue(Config) ->
333-
case rabbit_ct_broker_helpers:configured_metadata_store(Config) of
334-
mnesia ->
335-
{skip, "this validates a bugfix only implemented for Khperi"};
336-
_ ->
337-
passed = rabbit_ct_broker_helpers:rpc(
338-
Config, 0, ?MODULE, delete_exclusive_queue1, [Config])
339-
end.
334+
passed = rabbit_ct_broker_helpers:rpc(
335+
Config, 0, ?MODULE, delete_exclusive_queue1, [Config]).
340336

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

0 commit comments

Comments
 (0)