refactor(router): isolate cleanup logic in router module

This commit is contained in:
Andrew Mayorov 2023-08-07 22:28:37 +04:00
parent b74ff10705
commit 9eccfa0909
No known key found for this signature in database
GPG Key ID: 2837C62ACFBFED5D
2 changed files with 17 additions and 8 deletions

View File

@ -46,6 +46,8 @@
do_delete_route/2
]).
-export([cleanup_routes/1]).
-export([
match_routes/1,
lookup_routes/1,
@ -70,6 +72,8 @@
-type dest() :: node() | {group(), node()}.
-dialyzer({nowarn_function, [cleanup_routes/1]}).
%%--------------------------------------------------------------------
%% Mnesia bootstrap
%%--------------------------------------------------------------------
@ -196,6 +200,18 @@ print_routes(Topic) ->
match_routes(Topic)
).
-spec cleanup_routes(node()) -> ok.
cleanup_routes(Node) ->
Patterns = [
#route{_ = '_', dest = Node},
#route{_ = '_', dest = {'_', Node}}
],
[
mnesia:delete_object(?ROUTE_TAB, Route, write)
|| Pat <- Patterns,
Route <- mnesia:match_object(?ROUTE_TAB, Pat, write)
].
call(Router, Msg) ->
gen_server:call(Router, Msg, infinity).

View File

@ -197,11 +197,4 @@ stats_fun() ->
end.
cleanup_routes(Node) ->
Patterns = [
#route{_ = '_', dest = Node},
#route{_ = '_', dest = {'_', Node}}
],
[
mnesia:delete_object(?ROUTE_TAB, Route, write)
|| Pat <- Patterns, Route <- mnesia:match_object(?ROUTE_TAB, Pat, write)
].
emqx_router:cleanup_routes(Node).