@@ -397,23 +397,28 @@ delete(QueueName, Reason) ->
397397
398398delete_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+
13921412list_with_possible_retry_in_mnesia (Fun ) ->
13931413 % % amqqueue migration:
13941414 % % The `rabbit_queue' or `rabbit_durable_queue' tables
0 commit comments