Merge pull request #10528 from qzhuyan/perf/william/force-config-atom-path
perf(config): ensure root keys of 'conf' config is atom
This commit is contained in:
commit
b6c7e55348
|
@ -152,7 +152,7 @@ get_root([RootName | _]) ->
|
||||||
%% @doc For the given path, get raw root value enclosed in a single-key map.
|
%% @doc For the given path, get raw root value enclosed in a single-key map.
|
||||||
%% key is ensured to be binary.
|
%% key is ensured to be binary.
|
||||||
get_root_raw([RootName | _]) ->
|
get_root_raw([RootName | _]) ->
|
||||||
#{bin(RootName) => do_get_raw([RootName], #{})}.
|
#{bin(RootName) => get_raw([RootName], #{})}.
|
||||||
|
|
||||||
%% @doc Get a config value for the given path.
|
%% @doc Get a config value for the given path.
|
||||||
%% The path should at least include root config name.
|
%% The path should at least include root config name.
|
||||||
|
@ -231,14 +231,14 @@ find_listener_conf(Type, Listener, KeyPath) ->
|
||||||
put(Config) ->
|
put(Config) ->
|
||||||
maps:fold(
|
maps:fold(
|
||||||
fun(RootName, RootValue, _) ->
|
fun(RootName, RootValue, _) ->
|
||||||
?MODULE:put([RootName], RootValue)
|
?MODULE:put([atom(RootName)], RootValue)
|
||||||
end,
|
end,
|
||||||
ok,
|
ok,
|
||||||
Config
|
Config
|
||||||
).
|
).
|
||||||
|
|
||||||
erase(RootName) ->
|
erase(RootName) ->
|
||||||
persistent_term:erase(?PERSIS_KEY(?CONF, bin(RootName))),
|
persistent_term:erase(?PERSIS_KEY(?CONF, atom(RootName))),
|
||||||
persistent_term:erase(?PERSIS_KEY(?RAW_CONF, bin(RootName))),
|
persistent_term:erase(?PERSIS_KEY(?RAW_CONF, bin(RootName))),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
@ -287,9 +287,11 @@ get_default_value([RootName | _] = KeyPath) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec get_raw(emqx_utils_maps:config_key_path()) -> term().
|
-spec get_raw(emqx_utils_maps:config_key_path()) -> term().
|
||||||
|
get_raw([Root | T]) when is_atom(Root) -> get_raw([bin(Root) | T]);
|
||||||
get_raw(KeyPath) -> do_get_raw(KeyPath).
|
get_raw(KeyPath) -> do_get_raw(KeyPath).
|
||||||
|
|
||||||
-spec get_raw(emqx_utils_maps:config_key_path(), term()) -> term().
|
-spec get_raw(emqx_utils_maps:config_key_path(), term()) -> term().
|
||||||
|
get_raw([Root | T], Default) when is_atom(Root) -> get_raw([bin(Root) | T], Default);
|
||||||
get_raw(KeyPath, Default) -> do_get_raw(KeyPath, Default).
|
get_raw(KeyPath, Default) -> do_get_raw(KeyPath, Default).
|
||||||
|
|
||||||
-spec put_raw(map()) -> ok.
|
-spec put_raw(map()) -> ok.
|
||||||
|
@ -692,9 +694,9 @@ do_get(Type, [], Default) ->
|
||||||
false -> AllConf
|
false -> AllConf
|
||||||
end;
|
end;
|
||||||
do_get(Type, [RootName], Default) ->
|
do_get(Type, [RootName], Default) ->
|
||||||
persistent_term:get(?PERSIS_KEY(Type, bin(RootName)), Default);
|
persistent_term:get(?PERSIS_KEY(Type, RootName), Default);
|
||||||
do_get(Type, [RootName | KeyPath], Default) ->
|
do_get(Type, [RootName | KeyPath], Default) ->
|
||||||
RootV = persistent_term:get(?PERSIS_KEY(Type, bin(RootName)), #{}),
|
RootV = persistent_term:get(?PERSIS_KEY(Type, RootName), #{}),
|
||||||
do_deep_get(Type, KeyPath, RootV, Default).
|
do_deep_get(Type, KeyPath, RootV, Default).
|
||||||
|
|
||||||
do_put(Type, Putter, [], DeepValue) ->
|
do_put(Type, Putter, [], DeepValue) ->
|
||||||
|
@ -708,7 +710,7 @@ do_put(Type, Putter, [], DeepValue) ->
|
||||||
do_put(Type, Putter, [RootName | KeyPath], DeepValue) ->
|
do_put(Type, Putter, [RootName | KeyPath], DeepValue) ->
|
||||||
OldValue = do_get(Type, [RootName], #{}),
|
OldValue = do_get(Type, [RootName], #{}),
|
||||||
NewValue = do_deep_put(Type, Putter, KeyPath, OldValue, DeepValue),
|
NewValue = do_deep_put(Type, Putter, KeyPath, OldValue, DeepValue),
|
||||||
persistent_term:put(?PERSIS_KEY(Type, bin(RootName)), NewValue).
|
persistent_term:put(?PERSIS_KEY(Type, RootName), NewValue).
|
||||||
|
|
||||||
do_deep_get(?CONF, KeyPath, Map, Default) ->
|
do_deep_get(?CONF, KeyPath, Map, Default) ->
|
||||||
atom_conf_path(
|
atom_conf_path(
|
||||||
|
|
|
@ -177,7 +177,9 @@ t_sub_key_update_remove(_Config) ->
|
||||||
{ok, #{post_config_update => #{emqx_config_handler_SUITE => ok}}},
|
{ok, #{post_config_update => #{emqx_config_handler_SUITE => ok}}},
|
||||||
emqx:remove_config(KeyPath)
|
emqx:remove_config(KeyPath)
|
||||||
),
|
),
|
||||||
?assertError({config_not_found, KeyPath}, emqx:get_raw_config(KeyPath)),
|
?assertError(
|
||||||
|
{config_not_found, [<<"sysmon">>, os, cpu_check_interval]}, emqx:get_raw_config(KeyPath)
|
||||||
|
),
|
||||||
OSKey = maps:keys(emqx:get_raw_config([sysmon, os])),
|
OSKey = maps:keys(emqx:get_raw_config([sysmon, os])),
|
||||||
?assertEqual(false, lists:member(<<"cpu_check_interval">>, OSKey)),
|
?assertEqual(false, lists:member(<<"cpu_check_interval">>, OSKey)),
|
||||||
?assert(length(OSKey) > 0),
|
?assert(length(OSKey) > 0),
|
||||||
|
|
|
@ -274,7 +274,7 @@ t_load_unload_gateway(_) ->
|
||||||
|
|
||||||
?assertException(
|
?assertException(
|
||||||
error,
|
error,
|
||||||
{config_not_found, [gateway, stomp]},
|
{config_not_found, [<<"gateway">>, stomp]},
|
||||||
emqx:get_raw_config([gateway, stomp])
|
emqx:get_raw_config([gateway, stomp])
|
||||||
),
|
),
|
||||||
ok.
|
ok.
|
||||||
|
@ -307,7 +307,7 @@ t_load_remove_authn(_) ->
|
||||||
|
|
||||||
?assertException(
|
?assertException(
|
||||||
error,
|
error,
|
||||||
{config_not_found, [gateway, stomp, authentication]},
|
{config_not_found, [<<"gateway">>, stomp, authentication]},
|
||||||
emqx:get_raw_config([gateway, stomp, authentication])
|
emqx:get_raw_config([gateway, stomp, authentication])
|
||||||
),
|
),
|
||||||
ok.
|
ok.
|
||||||
|
@ -352,7 +352,7 @@ t_load_remove_listeners(_) ->
|
||||||
|
|
||||||
?assertException(
|
?assertException(
|
||||||
error,
|
error,
|
||||||
{config_not_found, [gateway, stomp, listeners, tcp, default]},
|
{config_not_found, [<<"gateway">>, stomp, listeners, tcp, default]},
|
||||||
emqx:get_raw_config([gateway, stomp, listeners, tcp, default])
|
emqx:get_raw_config([gateway, stomp, listeners, tcp, default])
|
||||||
),
|
),
|
||||||
ok.
|
ok.
|
||||||
|
@ -401,7 +401,7 @@ t_load_remove_listener_authn(_) ->
|
||||||
Path = [gateway, stomp, listeners, tcp, default, authentication],
|
Path = [gateway, stomp, listeners, tcp, default, authentication],
|
||||||
?assertException(
|
?assertException(
|
||||||
error,
|
error,
|
||||||
{config_not_found, Path},
|
{config_not_found, [<<"gateway">>, stomp, listeners, tcp, default, authentication]},
|
||||||
emqx:get_raw_config(Path)
|
emqx:get_raw_config(Path)
|
||||||
),
|
),
|
||||||
ok.
|
ok.
|
||||||
|
@ -421,7 +421,7 @@ t_load_gateway_with_certs_content(_) ->
|
||||||
assert_ssl_confs_files_deleted(SslConf),
|
assert_ssl_confs_files_deleted(SslConf),
|
||||||
?assertException(
|
?assertException(
|
||||||
error,
|
error,
|
||||||
{config_not_found, [gateway, stomp]},
|
{config_not_found, [<<"gateway">>, stomp]},
|
||||||
emqx:get_raw_config([gateway, stomp])
|
emqx:get_raw_config([gateway, stomp])
|
||||||
),
|
),
|
||||||
ok.
|
ok.
|
||||||
|
@ -489,7 +489,7 @@ t_add_listener_with_certs_content(_) ->
|
||||||
|
|
||||||
?assertException(
|
?assertException(
|
||||||
error,
|
error,
|
||||||
{config_not_found, [gateway, stomp, listeners, ssl, default]},
|
{config_not_found, [<<"gateway">>, stomp, listeners, ssl, default]},
|
||||||
emqx:get_raw_config([gateway, stomp, listeners, ssl, default])
|
emqx:get_raw_config([gateway, stomp, listeners, ssl, default])
|
||||||
),
|
),
|
||||||
ok.
|
ok.
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Reduce memory footprint in hot code path.
|
Loading…
Reference in New Issue