refactor(persistent_sessions): don't start session sup when disabled

This commit is contained in:
Tobias Lindahl 2021-10-26 09:54:41 +02:00
parent e3dc9b3f4f
commit 234641ccf4
2 changed files with 21 additions and 20 deletions

View File

@ -26,29 +26,29 @@ start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []). supervisor:start_link({local, ?MODULE}, ?MODULE, []).
init([]) -> init([]) ->
case emqx_persistent_session:is_store_enabled() of %% We want this supervisor to own the table for restarts
false -> SessionTab = emqx_session_router:create_init_tab(),
{ok, {{one_for_all, 0, 1}, []}};
true ->
%% We want this supervisor to own the table for restarts
SessionTab = emqx_session_router:create_init_tab(),
%% Resume worker sup %% Resume worker sup
ResumeSup = #{id => router_worker_sup, ResumeSup = #{id => router_worker_sup,
start => {emqx_session_router_worker_sup, start_link, [SessionTab]}, start => {emqx_session_router_worker_sup, start_link, [SessionTab]},
restart => permanent, restart => permanent,
shutdown => 2000, shutdown => 2000,
type => supervisor, type => supervisor,
modules => [emqx_session_router_worker_sup]}, modules => [emqx_session_router_worker_sup]},
SessionRouterPool = emqx_pool_sup:spec(session_router_pool, SessionRouterPool = emqx_pool_sup:spec(session_router_pool,
[session_router_pool, hash, [session_router_pool, hash,
{emqx_session_router, start_link, []}]), {emqx_session_router, start_link, []}]),
GCWorker = child_spec(emqx_persistent_session_gc, worker), GCWorker = child_spec(emqx_persistent_session_gc, worker),
{ok, {{one_for_all, 0, 1}, [ResumeSup, SessionRouterPool, GCWorker]}} Spec = #{ strategy => one_for_all
end. , intensity => 0
, period => 1
},
{ok, {Spec, [ResumeSup, SessionRouterPool, GCWorker]}}.
child_spec(Mod, worker) -> child_spec(Mod, worker) ->
#{id => Mod, #{id => Mod,

View File

@ -68,7 +68,8 @@ init([]) ->
SessionSup = child_spec(emqx_persistent_session_sup, supervisor), SessionSup = child_spec(emqx_persistent_session_sup, supervisor),
CMSup = child_spec(emqx_cm_sup, supervisor), CMSup = child_spec(emqx_cm_sup, supervisor),
SysSup = child_spec(emqx_sys_sup, supervisor), SysSup = child_spec(emqx_sys_sup, supervisor),
Children = [KernelSup, SessionSup] ++ Children = [KernelSup] ++
[SessionSup || emqx_persistent_session:is_store_enabled()] ++
[RouterSup || emqx_boot:is_enabled(router)] ++ [RouterSup || emqx_boot:is_enabled(router)] ++
[BrokerSup || emqx_boot:is_enabled(broker)] ++ [BrokerSup || emqx_boot:is_enabled(broker)] ++
[CMSup || emqx_boot:is_enabled(broker)] ++ [CMSup || emqx_boot:is_enabled(broker)] ++