fix: the file cluster-override.conf is emptied if hocon_pp:do/2 failed

This commit is contained in:
Shawn 2022-07-06 19:19:12 +08:00
parent 3674ab2e6e
commit 71f642518a
2 changed files with 8 additions and 5 deletions

View File

@ -511,11 +511,13 @@ get_root_names() ->
-spec save_configs(app_envs(), config(), raw_config(), raw_config(), update_opts()) ->
ok | {error, term()}.
save_configs(_AppEnvs, Conf, RawConf, OverrideConf, Opts) ->
%% We first try to save to override.conf, because saving to files is more error prone
%% than saving into memory.
save_to_override_conf(OverrideConf, Opts),
%% We may need also support hot config update for the apps that use application envs.
%% If that is the case uncomment the following line to update the configs to app env
%save_to_app_env(AppEnvs),
save_to_config_map(Conf, RawConf),
save_to_override_conf(OverrideConf, Opts).
%save_to_app_env(_AppEnvs),
save_to_config_map(Conf, RawConf).
-spec save_to_app_env([tuple()]) -> ok.
save_to_app_env(AppEnvs) ->

View File

@ -452,8 +452,9 @@ merge_to_old_config(UpdateReq, _RawConf) ->
%% local-override.conf priority is higher than cluster-override.conf
%% If we want cluster to take effect, we must remove the local.
remove_from_local_if_cluster_change(BinKeyPath, #{override_to := cluster} = Opts) ->
Local = remove_from_override_config(BinKeyPath, Opts#{override_to => local}),
_ = emqx_config:save_to_override_conf(Local, Opts),
Opts1 = Opts#{override_to => local},
Local = remove_from_override_config(BinKeyPath, Opts1),
_ = emqx_config:save_to_override_conf(Local, Opts1),
ok;
remove_from_local_if_cluster_change(_BinKeyPath, _Opts) ->
ok.