Skip to content

Commit 350b55c

Browse files
committed
Improve function names
Improve function names and add function specs.
1 parent 3a3398f commit 350b55c

2 files changed

Lines changed: 48 additions & 51 deletions

File tree

deps/rabbit/src/rabbit_db_topic_exchange.erl

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ match(#resource{virtual_host = VHost, name = XName} = X, RoutingKey, Opts) ->
4646
[]
4747
end;
4848
_ ->
49-
trie_match_in_khepri(X, Words, BKeys)
49+
trie_match_v3(X, Words, BKeys)
5050
end.
5151

5252
-spec split_topic_key_binary(RoutingKey) -> Words when
@@ -170,69 +170,49 @@ format_dest_bkeys([{#resource{kind = queue} = Dest, BKey} | Rest], Acc) ->
170170
format_dest_bkeys([{Dest, _BKey} | Rest], Acc) ->
171171
format_dest_bkeys(Rest, [Dest | Acc]).
172172

173-
%% --------------------------------------------------------------
174-
%% Internal
175-
%% --------------------------------------------------------------
176-
177-
-spec add_matched([rabbit_types:binding_destination() |
178-
{rabbit_types:binding_destination(), BindingArgs :: list()}],
179-
ReturnBindingKeys :: boolean(),
180-
match_result()) ->
181-
match_result().
182-
add_matched(Destinations, false, Acc) ->
183-
Destinations ++ Acc;
184-
add_matched(DestinationsArgs, true, Acc) ->
185-
lists:foldl(
186-
fun({DestQ = #resource{kind = queue}, BindingArgs}, L) ->
187-
case rabbit_misc:table_lookup(BindingArgs, <<"x-binding-key">>) of
188-
{longstr, BKey} ->
189-
[{DestQ, BKey} | L];
190-
_ ->
191-
[DestQ | L]
192-
end;
193-
({DestX, _BindingArgs}, L) ->
194-
[DestX | L]
195-
end, Acc, DestinationsArgs).
196-
197-
%% Khepri topic graph
173+
%% ==============================================================
174+
%% Old v3 Khepri topic graph.
175+
%% Delete these *_v3 functions when feature flag
176+
%% topic_binding_projection_v4 becomes required.
177+
%% ==============================================================
198178

199-
trie_match_in_khepri(X, Words, BKeys) ->
179+
trie_match_v3(X, Words, BKeys) ->
200180
try
201-
trie_match_in_khepri(X, root, Words, BKeys, [])
181+
trie_match_v3(X, root, Words, BKeys, [])
202182
catch
203183
error:badarg ->
204184
[]
205185
end.
206186

207-
trie_match_in_khepri(X, Node, [], BKeys, ResAcc0) ->
208-
Destinations = trie_bindings_in_khepri(X, Node, BKeys),
209-
ResAcc = add_matched(Destinations, BKeys, ResAcc0),
210-
trie_match_part_in_khepri(
187+
trie_match_v3(X, Node, [], BKeys, ResAcc0) ->
188+
Destinations = trie_bindings_v3(X, Node, BKeys),
189+
ResAcc = add_matched_v3(Destinations, BKeys, ResAcc0),
190+
trie_match_part_v3(
211191
X, Node, <<"#">>,
212-
fun trie_match_skip_any_in_khepri/5, [], BKeys, ResAcc);
213-
trie_match_in_khepri(X, Node, [W | RestW] = Words, BKeys, ResAcc) ->
192+
fun trie_match_skip_any_v3/5, [], BKeys, ResAcc);
193+
trie_match_v3(X, Node, [W | RestW] = Words, BKeys, ResAcc) ->
214194
lists:foldl(fun ({WArg, MatchFun, RestWArg}, Acc) ->
215-
trie_match_part_in_khepri(
195+
trie_match_part_v3(
216196
X, Node, WArg, MatchFun, RestWArg, BKeys, Acc)
217-
end, ResAcc, [{W, fun trie_match_in_khepri/5, RestW},
218-
{<<"*">>, fun trie_match_in_khepri/5, RestW},
197+
end, ResAcc, [{W, fun trie_match_v3/5, RestW},
198+
{<<"*">>, fun trie_match_v3/5, RestW},
219199
{<<"#">>,
220-
fun trie_match_skip_any_in_khepri/5, Words}]).
200+
fun trie_match_skip_any_v3/5, Words}]).
221201

222-
trie_match_part_in_khepri(X, Node, Search, MatchFun, RestW, BKeys, ResAcc) ->
223-
case trie_child_in_khepri(X, Node, Search) of
202+
trie_match_part_v3(X, Node, Search, MatchFun, RestW, BKeys, ResAcc) ->
203+
case trie_child_v3(X, Node, Search) of
224204
{ok, NextNode} -> MatchFun(X, NextNode, RestW, BKeys, ResAcc);
225205
error -> ResAcc
226206
end.
227207

228-
trie_match_skip_any_in_khepri(X, Node, [], BKeys, ResAcc) ->
229-
trie_match_in_khepri(X, Node, [], BKeys, ResAcc);
230-
trie_match_skip_any_in_khepri(X, Node, [_ | RestW] = Words, BKeys, ResAcc) ->
231-
trie_match_skip_any_in_khepri(
208+
trie_match_skip_any_v3(X, Node, [], BKeys, ResAcc) ->
209+
trie_match_v3(X, Node, [], BKeys, ResAcc);
210+
trie_match_skip_any_v3(X, Node, [_ | RestW] = Words, BKeys, ResAcc) ->
211+
trie_match_skip_any_v3(
232212
X, Node, RestW, BKeys,
233-
trie_match_in_khepri(X, Node, Words, BKeys, ResAcc)).
213+
trie_match_v3(X, Node, Words, BKeys, ResAcc)).
234214

235-
trie_child_in_khepri(X, Node, Word) ->
215+
trie_child_v3(X, Node, Word) ->
236216
case ets:lookup(
237217
?KHEPRI_PROJECTION_V3,
238218
#trie_edge{exchange_name = X,
@@ -242,7 +222,7 @@ trie_child_in_khepri(X, Node, Word) ->
242222
[] -> error
243223
end.
244224

245-
trie_bindings_in_khepri(X, Node, BKeys) ->
225+
trie_bindings_v3(X, Node, BKeys) ->
246226
case ets:lookup(
247227
?KHEPRI_PROJECTION_V3,
248228
#trie_edge{exchange_name = X,
@@ -259,3 +239,18 @@ trie_bindings_in_khepri(X, Node, BKeys) ->
259239
[] ->
260240
[]
261241
end.
242+
243+
add_matched_v3(Destinations, false, Acc) ->
244+
Destinations ++ Acc;
245+
add_matched_v3(DestinationsArgs, true, Acc) ->
246+
lists:foldl(
247+
fun({DestQ = #resource{kind = queue}, BindingArgs}, L) ->
248+
case rabbit_misc:table_lookup(BindingArgs, <<"x-binding-key">>) of
249+
{longstr, BKey} ->
250+
[{DestQ, BKey} | L];
251+
_ ->
252+
[DestQ | L]
253+
end;
254+
({DestX, _BindingArgs}, L) ->
255+
[DestX | L]
256+
end, Acc, DestinationsArgs).

deps/rabbit/src/rabbit_khepri.erl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179

180180
%% Called remotely to handle unregistration of old projections.
181181
-export([supports_rabbit_khepri_topic_trie_v2/0,
182-
supports_rabbit_khepri_topic_trie_version/0]).
182+
supported_topic_trie_version/0]).
183183

184184
%% Called locally to determine which projection to use.
185185
-export([get_effective_topic_binding_projection_version/0]).
@@ -1708,7 +1708,7 @@ register_rabbit_topic_trie_projection() ->
17081708
end,
17091709
Projection = khepri_projection:new(rabbit_khepri_topic_trie_v4, PFun, Opts),
17101710
PathPattern = topic_binding_path_pattern(),
1711-
_ = unregister_old_rabbit_topic_trie_projections(),
1711+
unregister_old_rabbit_topic_trie_projections(),
17121712
khepri:register_projection(?STORE_ID, PathPattern, Projection).
17131713

17141714
topic_binding_path_pattern() ->
@@ -1799,10 +1799,12 @@ trie_node_has_bindings(BindingTab, NodeId) ->
17991799
_ -> false
18001800
end.
18011801

1802+
-spec supports_rabbit_khepri_topic_trie_v2() -> boolean().
18021803
supports_rabbit_khepri_topic_trie_v2() ->
18031804
true.
18041805

1805-
supports_rabbit_khepri_topic_trie_version() ->
1806+
-spec supported_topic_trie_version() -> non_neg_integer().
1807+
supported_topic_trie_version() ->
18061808
4.
18071809

18081810
get_effective_topic_binding_projection_version() ->
@@ -1860,7 +1862,7 @@ unregister_old_rabbit_topic_trie_projection({Version, ProjectionName}) ->
18601862
_ ->
18611863
erpc:multicall(
18621864
Nodes,
1863-
?MODULE, supports_rabbit_khepri_topic_trie_version, [])
1865+
?MODULE, supported_topic_trie_version, [])
18641866
end,
18651867
SupportedEverywhere = lists:all(
18661868
fun

0 commit comments

Comments
 (0)