fix(retainer): fix that EMQX can't start when the retainer is disabled

This commit is contained in:
firest 2022-09-07 12:11:57 +08:00
parent 2943cbc261
commit de36b77261
2 changed files with 14 additions and 6 deletions

View File

@ -348,16 +348,12 @@ enable_retainer(
#{context_id := ContextId} = State, #{context_id := ContextId} = State,
#{ #{
msg_clear_interval := ClearInterval, msg_clear_interval := ClearInterval,
backend := BackendCfg, backend := BackendCfg
flow_control := FlowControl
} }
) -> ) ->
NewContextId = ContextId + 1, NewContextId = ContextId + 1,
Context = create_resource(new_context(NewContextId), BackendCfg), Context = create_resource(new_context(NewContextId), BackendCfg),
load(Context), load(Context),
emqx_limiter_server:add_bucket(
?APP, internal, maps:get(batch_deliver_limiter, FlowControl, undefined)
),
State#{ State#{
enable := true, enable := true,
context_id := NewContextId, context_id := NewContextId,
@ -373,7 +369,6 @@ disable_retainer(
} = State } = State
) -> ) ->
unload(), unload(),
emqx_limiter_server:del_bucket(?APP, internal),
ok = close_resource(Context), ok = close_resource(Context),
State#{ State#{
enable := false, enable := false,

View File

@ -18,6 +18,8 @@
-behaviour(application). -behaviour(application).
-include("emqx_retainer.hrl").
-export([ -export([
start/2, start/2,
stop/1 stop/1
@ -25,8 +27,19 @@
start(_Type, _Args) -> start(_Type, _Args) ->
ok = emqx_retainer_mnesia_cli:load(), ok = emqx_retainer_mnesia_cli:load(),
init_bucket(),
emqx_retainer_sup:start_link(). emqx_retainer_sup:start_link().
stop(_State) -> stop(_State) ->
ok = emqx_retainer_mnesia_cli:unload(), ok = emqx_retainer_mnesia_cli:unload(),
delete_bucket(),
ok. ok.
init_bucket() ->
#{flow_control := FlowControl} = emqx:get_config([retainer]),
emqx_limiter_server:add_bucket(
?APP, internal, maps:get(batch_deliver_limiter, FlowControl, undefined)
).
delete_bucket() ->
emqx_limiter_server:del_bucket(?APP, internal).