nickva commented on code in PR #5762:
URL: https://github.com/apache/couchdb/pull/5762#discussion_r2561341772
##########
src/config/src/config.erl:
##########
@@ -615,6 +584,56 @@ settings_fmap_fun({{?MODULE, ?SETTINGS, Sec, Key}, Val}) ->
settings_fmap_fun(_) ->
false.
+reload(Config) ->
+ #config{ini_files_dirs = IniFilesDirs} = Config,
+ IniFiles = expand_dirs(IniFilesDirs),
+ % Update ets with ini values.
+ IniMap = ini_map(IniFiles),
+ maps:foreach(
+ fun({Sec, Key}, V) ->
+ VExisting = get_value(Sec, Key, undefined),
+ put_value(Sec, Key, V),
+ case V =:= VExisting of
+ true ->
+ ok;
+ false ->
+ Msg = "Reload detected config change ~s.~s = ~p",
+ Args = [Sec, Key, maybe_conceal(V, is_sensitive(Sec,
Key))],
+ couch_log:notice(Msg, Args),
+ Event = {config_change, Sec, Key, V, true},
+ gen_event:sync_notify(config_event, Event)
+ end
+ end,
+ IniMap
+ ),
+ % And remove anything in ets that wasn't on disk.
+ lists:foreach(
+ fun
+ ({{Sec, Key}, _}) when not is_map_key({Sec, Key}, IniMap) ->
+ NoticeMsg = "Reload deleting in-memory config ~s.~s",
+ couch_log:notice(NoticeMsg, [Sec, Key]),
+ erase_value(Sec, Key),
+ Event = {config_change, Sec, Key, deleted, true},
+ gen_event:sync_notify(config_event, Event);
+ (_) ->
+ ok
+ end,
+ all()
+ ),
+ Config#config{
+ ini_files = IniFiles,
+ write_filename = get_write_file(IniFiles)
+ }.
+
+maybe_schedule_reload() ->
+ case get_integer("config", "auto_reload_secs", 0) of
+ 0 ->
+ ignore;
+ AutoReloadSecs when AutoReloadSecs > 0 ->
+ AutoReloadMS = erlang:convert_time_unit(AutoReloadSecs, second,
millisecond),
+ erlang:send_after(AutoReloadMS, ?MODULE, reload)
Review Comment:
To avoid the chance of events piling up, keep track of the timer reference
and always cancel the previous before scheduling a new one.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]