Skip to content

Commit

Permalink
Kill snapshot process before deleting everything
Browse files Browse the repository at this point in the history
if there is a snapshot process pending it could cause the directory
deletion to fail, best kill the snapshot process first
  • Loading branch information
kjnilsson committed Aug 8, 2024
1 parent d590c4e commit cd6b48f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/ra_log.erl
Original file line number Diff line number Diff line change
Expand Up @@ -933,8 +933,24 @@ read_config(Dir) ->
ra_lib:consult(ConfigPath).

-spec delete_everything(state()) -> ok.
delete_everything(#?MODULE{cfg = #cfg{directory = Dir}} = Log) ->
delete_everything(#?MODULE{cfg = #cfg{directory = Dir},
snapshot_state = SnapState} = Log) ->
_ = close(Log),
%% if there is a snapshot process pending it could cause the directory
%% deletion to fail, best kill the snapshot process first
case ra_snapshot:pending(SnapState) of
{Pid, _, _} ->
case is_process_alive(Pid) of
true ->
exit(Pid, kill),
timer:sleep(100),
ok;
false ->
ok
end;
_ ->
ok
end,
try ra_lib:recursive_delete(Dir) of
ok -> ok
catch
Expand Down

0 comments on commit cd6b48f

Please sign in to comment.