summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rabbit_exchange_type_topic.erl58
1 files changed, 33 insertions, 25 deletions
diff --git a/src/rabbit_exchange_type_topic.erl b/src/rabbit_exchange_type_topic.erl
index 7ff0808ea6..f9ac69ba1e 100644
--- a/src/rabbit_exchange_type_topic.erl
+++ b/src/rabbit_exchange_type_topic.erl
@@ -72,8 +72,9 @@ remove_bindings(true, X, Bs) ->
lists:foldl(
fun(B = #binding{destination = D}, {Acc, PathAcc}) ->
Path = [{FinalNode, _} | _] = binding_path(B),
- PathAcc1 = decrement_bindings(Path,
- maybe_add_path(Path, PathAcc)),
+ PathAcc1 = decrement_bindings(X, Path,
+ maybe_add_path(X, Path,
+ PathAcc)),
{[{FinalNode, D} | Acc], PathAcc1}
end, {[], gb_trees:empty()}, Bs),
@@ -85,38 +86,43 @@ remove_bindings(true, X, Bs) ->
remove_bindings(false, _X, _Bs) ->
ok.
-maybe_add_path([{root, none}], PathAcc) ->
+maybe_add_path(_X, [{root, none}], PathAcc) ->
PathAcc;
-maybe_add_path(Path, PathAcc) ->
- case gb_trees:is_defined(Path, PathAcc) of
+maybe_add_path(X, Path = [{Node, _} | _], PathAcc) ->
+ case gb_trees:is_defined(Node, PathAcc) of
true -> PathAcc;
- false -> gb_trees:insert(Path, counts(Path), PathAcc)
+ false -> gb_trees:insert(Node, path_entry(X, Path), PathAcc)
end.
-decrement_bindings(Path, PathAcc) ->
- with_path_acc(fun({Bindings, Edges}) -> {Bindings - 1, Edges} end,
+decrement_bindings(X, Path, PathAcc) ->
+ with_path_acc(X,
+ fun({_Path, Bindings, Edges}) ->
+ {Path, Bindings - 1, Edges}
+ end,
Path, PathAcc).
-decrement_edges(Path, PathAcc) ->
- with_path_acc(fun({Bindings, Edges}) -> {Bindings, Edges - 1} end,
+decrement_edges(X, Path, PathAcc) ->
+ with_path_acc(X,
+ fun({_Path, Bindings, Edges}) ->
+ {Path, Bindings, Edges - 1}
+ end,
Path, PathAcc).
-with_path_acc(_Fun, [{root, none}], PathAcc) ->
+with_path_acc(_X, _Fun, [{root, none}], PathAcc) ->
PathAcc;
-with_path_acc(Fun, Path, PathAcc) ->
- NewVal = Fun(gb_trees:get(Path, PathAcc)),
- NewPathAcc = gb_trees:update(Path, NewVal, PathAcc),
+with_path_acc(X, Fun, [{Node, _} | ParentPath], PathAcc) ->
+ NewVal = Fun(gb_trees:get(Node, PathAcc)),
+ NewPathAcc = gb_trees:update(Node, NewVal, PathAcc),
case NewVal of
{0, 0} ->
- [_ | ParentPath] = Path,
- decrement_edges(ParentPath,
- maybe_add_path(ParentPath, NewPathAcc));
+ decrement_edges(X, ParentPath,
+ maybe_add_path(X, ParentPath, NewPathAcc));
_ ->
NewPathAcc
end.
-counts([{FinalNode, _} | _]) ->
- {trie_binding_count(FinalNode), trie_child_count(FinalNode)}.
+path_entry(X, Path = [{Node, _} | _]) ->
+ {Path, trie_binding_count(X, Node), trie_child_count(X, Node)}.
binding_path(#binding{source = X, key = K}) ->
follow_down_get_path(X, split_topic_key(K)).
@@ -232,17 +238,19 @@ trie_binding_op(X, Node, D, Op) ->
destination = D}},
write).
-trie_child_count(Node) ->
+trie_child_count(X, Node) ->
count(rabbit_topic_trie_edge,
- #topic_trie_edge{trie_edge = #trie_edge{node_id = Node,
- _ = '_'},
+ #topic_trie_edge{trie_edge = #trie_edge{exchange_name = X,
+ node_id = Node,
+ _ = '_'},
_ = '_'}).
-trie_binding_count(Node) ->
+trie_binding_count(X, Node) ->
count(rabbit_topic_trie_binding,
#topic_trie_binding{
- trie_binding = #trie_binding{node_id = Node,
- _ = '_'},
+ trie_binding = #trie_binding{exchange_name = X,
+ node_id = Node,
+ _ = '_'},
_ = '_'}).
count(Table, Match) ->