Skip to content

Commit

Permalink
Write config to temp file then move
Browse files Browse the repository at this point in the history
Instead of overwriting in place. This should be safer and reduce
changes of config file corruptions that could cause members to
become unable to restart.
  • Loading branch information
kjnilsson committed Jun 13, 2023
1 parent 0422ef4 commit cbe9e56
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ra_log.erl
Original file line number Diff line number Diff line change
Expand Up @@ -724,15 +724,17 @@ overview(#?MODULE{last_index = LastIndex,
-spec write_config(ra_server:config(), state()) -> ok.
write_config(Config0, #?MODULE{cfg = #cfg{directory = Dir}}) ->
ConfigPath = filename:join(Dir, "config"),
TmpConfigPath = filename:join(Dir, "config.tmp"),
% clean config of potentially unserialisable data
Config = maps:without([parent,
counter,
has_changed,
%% don't write system config to disk as it will
%% be updated each time
system_config], Config0),
ok = ra_lib:write_file(ConfigPath,
ok = ra_lib:write_file(TmpConfigPath,
list_to_binary(io_lib:format("~p.", [Config]))),
ok = prim_file:rename(TmpConfigPath, ConfigPath),
ok.

-spec read_config(state() | file:filename()) ->
Expand Down

0 comments on commit cbe9e56

Please sign in to comment.