Skip to content

Commit 868b41e

Browse files
committed
rabbit_db_binding: Prefer khepri_tx_adv:delete_many/1 to delete bindings
Currently we use a combination of `khepri_tx:get_many/1` and then either `khepri_tx:delete/1` or `khepri_tx:delete_many/1`. This isn't a functional change: switching to `khepri_tx_adv:delete_many/1` is essentially equivalent but performs the deletion and lookup all in one command and one traversal of the tree. This should improve performance when deleting many bindings in an exchange.
1 parent 067b038 commit 868b41e

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

deps/rabbit/src/rabbit_db_binding.erl

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -835,9 +835,8 @@ delete_for_source_in_khepri(#resource{virtual_host = VHost, name = Name}) ->
835835
_Kind = ?KHEPRI_WILDCARD_STAR,
836836
_DstName = ?KHEPRI_WILDCARD_STAR,
837837
_RoutingKey = #if_has_data{}),
838-
{ok, Bindings} = khepri_tx:get_many(Path),
839-
ok = khepri_tx:delete_many(Path),
840-
maps:fold(fun(_P, Set, Acc) ->
838+
{ok, Bindings} = khepri_tx_adv:delete_many(Path),
839+
maps:fold(fun(_P, #{data := Set}, Acc) ->
841840
sets:to_list(Set) ++ Acc
842841
end, [], Bindings).
843842

@@ -881,25 +880,20 @@ delete_for_destination_in_mnesia(DstName, OnlyDurable, Fun) ->
881880
OnlyDurable :: boolean(),
882881
Deletions :: rabbit_binding:deletions().
883882

884-
delete_for_destination_in_khepri(DstName, OnlyDurable) ->
885-
BindingsMap = match_destination_in_khepri(DstName),
886-
maps:foreach(fun(K, _V) -> khepri_tx:delete(K) end, BindingsMap),
887-
Bindings = maps:fold(fun(_, Set, Acc) ->
883+
delete_for_destination_in_khepri(#resource{virtual_host = VHost, kind = Kind, name = Name}, OnlyDurable) ->
884+
Pattern = khepri_route_path(
885+
VHost,
886+
_SrcName = ?KHEPRI_WILDCARD_STAR,
887+
Kind,
888+
Name,
889+
_RoutingKey = ?KHEPRI_WILDCARD_STAR),
890+
{ok, BindingsMap} = khepri_tx_adv:delete_many(Pattern),
891+
Bindings = maps:fold(fun(_, #{data := Set}, Acc) ->
888892
sets:to_list(Set) ++ Acc
889893
end, [], BindingsMap),
890894
rabbit_binding:group_bindings_fold(fun maybe_auto_delete_exchange_in_khepri/4,
891895
lists:keysort(#binding.source, Bindings), OnlyDurable).
892896

893-
match_destination_in_khepri(#resource{virtual_host = VHost, kind = Kind, name = Name}) ->
894-
Path = khepri_route_path(
895-
VHost,
896-
_SrcName = ?KHEPRI_WILDCARD_STAR,
897-
Kind,
898-
Name,
899-
_RoutingKey = ?KHEPRI_WILDCARD_STAR),
900-
{ok, Map} = khepri_tx:get_many(Path),
901-
Map.
902-
903897
%% -------------------------------------------------------------------
904898
%% delete_transient_for_destination_in_mnesia().
905899
%% -------------------------------------------------------------------

0 commit comments

Comments
 (0)