fix(limiter): fix elvis && dialyzer error
This commit is contained in:
parent
d3f965dfe7
commit
dbab1bc96a
|
@ -75,11 +75,11 @@
|
|||
|
||||
-type state() :: #{
|
||||
type := limiter_type(),
|
||||
root := undefined | root(),
|
||||
root := root(),
|
||||
buckets := buckets(),
|
||||
%% current counter to alloc
|
||||
counter := undefined | counters:counters_ref(),
|
||||
index := index()
|
||||
counter := counters:counters_ref(),
|
||||
index := 0 | index()
|
||||
}.
|
||||
|
||||
-type buckets() :: #{bucket_name() => bucket()}.
|
||||
|
@ -507,7 +507,7 @@ do_add_bucket(Id, #{rate := Rate, capacity := Capacity} = Cfg, #{buckets := Buck
|
|||
end.
|
||||
|
||||
make_bucket(Id, Cfg, #{index := ?COUNTER_SIZE} = State) ->
|
||||
add_bucket(Id, Cfg, State#{
|
||||
make_bucket(Id, Cfg, State#{
|
||||
counter => counters:new(?COUNTER_SIZE, [write_concurrency]),
|
||||
index => 0
|
||||
});
|
||||
|
|
|
@ -546,7 +546,7 @@ add_limiter_bucket(Id, #{limiter := Limiters}) ->
|
|||
ok,
|
||||
Limiters
|
||||
);
|
||||
add_limiter_bucket(_Id, _cfg) ->
|
||||
add_limiter_bucket(_Id, _Cfg) ->
|
||||
ok.
|
||||
|
||||
del_limiter_bucket(Id, #{limiter := Limiters}) ->
|
||||
|
@ -556,7 +556,7 @@ del_limiter_bucket(Id, #{limiter := Limiters}) ->
|
|||
end,
|
||||
maps:keys(Limiters)
|
||||
);
|
||||
del_limiter_bucket(_Id, _cfg) ->
|
||||
del_limiter_bucket(_Id, _Cfg) ->
|
||||
ok.
|
||||
|
||||
enable_authn(Opts) ->
|
||||
|
|
|
@ -151,13 +151,8 @@ config(get, _) ->
|
|||
{200, emqx:get_raw_config([retainer])};
|
||||
config(put, #{body := Body}) ->
|
||||
try
|
||||
check_bucket_exists(
|
||||
Body,
|
||||
fun(Conf) ->
|
||||
{ok, _} = emqx_retainer:update_config(Conf),
|
||||
{200, emqx:get_raw_config([retainer])}
|
||||
end
|
||||
)
|
||||
{ok, _} = emqx_retainer:update_config(Body),
|
||||
{200, emqx:get_raw_config([retainer])}
|
||||
catch
|
||||
_:Reason:_ ->
|
||||
{400, #{
|
||||
|
@ -237,30 +232,3 @@ check_backend(Type, Params, Cont) ->
|
|||
_ ->
|
||||
{400, 'BAD_REQUEST', <<"This API only support built in database">>}
|
||||
end.
|
||||
|
||||
check_bucket_exists(
|
||||
#{
|
||||
<<"flow_control">> :=
|
||||
#{<<"batch_deliver_limiter">> := Name} = Flow
|
||||
} = Conf,
|
||||
Cont
|
||||
) ->
|
||||
case erlang:binary_to_atom(Name) of
|
||||
'' ->
|
||||
%% workaround, empty string means set the value to undefined,
|
||||
%% but now, we can't store `undefined` in the config file correct,
|
||||
%% but, we can delete this field
|
||||
Cont(Conf#{
|
||||
<<"flow_control">> := maps:remove(<<"batch_deliver_limiter">>, Flow)
|
||||
});
|
||||
Bucket ->
|
||||
Path = emqx_limiter_schema:get_bucket_cfg_path(batch, Bucket),
|
||||
case emqx:get_config(Path, undefined) of
|
||||
undefined ->
|
||||
{400, 'BAD_REQUEST', <<"The limiter bucket not exists">>};
|
||||
_ ->
|
||||
Cont(Conf)
|
||||
end
|
||||
end;
|
||||
check_bucket_exists(Conf, Cont) ->
|
||||
Cont(Conf).
|
||||
|
|
Loading…
Reference in New Issue