@@ -399,23 +399,28 @@ delete(QueueName, Reason) ->
399399
400400delete_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+
14601480list_with_possible_retry_in_mnesia (Fun ) ->
14611481 % % amqqueue migration:
14621482 % % The `rabbit_queue' or `rabbit_durable_queue' tables
0 commit comments