Merge pull request #13082 from SergeTupchiy/routes-fixes

Minor routes fixes
This commit is contained in:
SergeTupchiy 2024-05-21 19:11:47 +03:00 committed by GitHub
commit 528d6b7ef1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 7 deletions

View File

@ -46,9 +46,10 @@
-export([has_route/2]). -export([has_route/2]).
-endif. -endif.
-type route() :: #ps_route{}.
-type dest() :: emqx_persistent_session_ds:id(). -type dest() :: emqx_persistent_session_ds:id().
-export_type([dest/0]). -export_type([dest/0, route/0]).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Table Initialization %% Table Initialization
@ -123,19 +124,19 @@ has_any_route(Topic) ->
%% @doc Take a real topic (not filter) as input, return the matching topics and topic %% @doc Take a real topic (not filter) as input, return the matching topics and topic
%% filters associated with route destination. %% filters associated with route destination.
-spec match_routes(emqx_types:topic()) -> [emqx_types:route()]. -spec match_routes(emqx_types:topic()) -> [route()].
match_routes(Topic) when is_binary(Topic) -> match_routes(Topic) when is_binary(Topic) ->
lookup_route_tab(Topic) ++ lookup_route_tab(Topic) ++
[match_to_route(M) || M <- match_filters(Topic)]. [match_to_route(M) || M <- match_filters(Topic)].
%% @doc Take a topic or filter as input, and return the existing routes with exactly %% @doc Take a topic or filter as input, and return the existing routes with exactly
%% this topic or filter. %% this topic or filter.
-spec lookup_routes(emqx_types:topic()) -> [emqx_types:route()]. -spec lookup_routes(emqx_types:topic()) -> [route()].
lookup_routes(Topic) -> lookup_routes(Topic) ->
case emqx_topic:wildcard(Topic) of case emqx_topic:wildcard(Topic) of
true -> true ->
Pat = #ps_routeidx{entry = emqx_topic_index:make_key(Topic, '$1')}, Pat = #ps_routeidx{entry = emqx_topic_index:make_key(Topic, '$1')},
[Dest || [Dest] <- ets:match(?PS_FILTERS_TAB, Pat)]; [#ps_route{topic = Topic, dest = Dest} || [Dest] <- ets:match(?PS_FILTERS_TAB, Pat)];
false -> false ->
lookup_route_tab(Topic) lookup_route_tab(Topic)
end. end.
@ -194,11 +195,11 @@ cleanup_routes(DSSessionId) ->
?PS_ROUTER_TAB ?PS_ROUTER_TAB
). ).
-spec foldl_routes(fun((emqx_types:route(), Acc) -> Acc), Acc) -> Acc. -spec foldl_routes(fun((route(), Acc) -> Acc), Acc) -> Acc.
foldl_routes(FoldFun, AccIn) -> foldl_routes(FoldFun, AccIn) ->
fold_routes(foldl, FoldFun, AccIn). fold_routes(foldl, FoldFun, AccIn).
-spec foldr_routes(fun((emqx_types:route(), Acc) -> Acc), Acc) -> Acc. -spec foldr_routes(fun((route(), Acc) -> Acc), Acc) -> Acc.
foldr_routes(FoldFun, AccIn) -> foldr_routes(FoldFun, AccIn) ->
fold_routes(foldr, FoldFun, AccIn). fold_routes(foldr, FoldFun, AccIn).

View File

@ -512,7 +512,7 @@ lookup_routes_v2(Topic) ->
case emqx_topic:wildcard(Topic) of case emqx_topic:wildcard(Topic) of
true -> true ->
Pat = #routeidx{entry = emqx_topic_index:make_key(Topic, '$1')}, Pat = #routeidx{entry = emqx_topic_index:make_key(Topic, '$1')},
[Dest || [Dest] <- ets:match(?ROUTE_TAB_FILTERS, Pat)]; [#route{topic = Topic, dest = Dest} || [Dest] <- ets:match(?ROUTE_TAB_FILTERS, Pat)];
false -> false ->
lookup_route_tab(Topic) lookup_route_tab(Topic)
end. end.