Last active
March 25, 2026 07:13
-
-
Save zmstone/d045c4a3ee66d1b5f4416045d89b0c65 to your computer and use it in GitHub Desktop.
find missing route in EMQX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %% This file provides two Erlang expressions to be evaluated in 'emqx remote_console' | |
| %% to check if there is any missing route for existing subscriptions in local EMQX node. | |
| %% The expected result should be [], if it's not [], it might be due to inflight replication | |
| %% of routes especially for 'replicant' nodes. | |
| %% 1. Define a function. | |
| FindMissingRouteBatch = fun FindMissingRouteBatch(Cursor0, Limit) -> | |
| Key0 = case Cursor0 of | |
| undefined -> ets:first(emqx_channel); | |
| _ -> Cursor0 | |
| end, | |
| F = fun F(Key, N, Acc) -> | |
| case ets:lookup(emqx_channel, Key) of | |
| [] -> | |
| {lists:reverse(Acc), Key}; | |
| Chans -> | |
| Rows = lists:flatmap(fun({ClientId, ChanPid}) -> | |
| [{ClientId, ChanPid, Topic} || is_pid(ChanPid), {Topic, _SubOpts} | |
| <- emqx_broker:subscriptions(ChanPid), | |
| is_binary(Topic), | |
| not emqx_router:has_route(Topic, node())] | |
| end, Chans), | |
| case length(Rows) of | |
| C when C < N -> | |
| F(ets:next(emqx_channel, Key), N - C, lists:reverse(Rows) ++ Acc); | |
| _ -> | |
| Taken = lists:sublist(Rows, N), | |
| {lists:reverse(Taken ++ Acc), ets:next(emqx_channel, Key)} | |
| end | |
| end | |
| end, | |
| F(Key0, Limit, []) | |
| end. | |
| %% Evaluate the function | |
| FindMissingRouteBatch(undefined, 100). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment