Skip to content

Commit

Permalink
Merge branch 'maint'
Browse files Browse the repository at this point in the history
* maint:
  mnesia: Delay old backup deletion
  • Loading branch information
dgud committed Aug 15, 2023
2 parents f9d50e4 + 8fd0144 commit 3168fcf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/mnesia/src/mnesia_backup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ open_write(OpaqueData) ->
File = OpaqueData,
Tmp = lists:concat([File,".BUPTMP"]),
file:delete(Tmp),
file:delete(File),
case disk_log:open([{name, make_ref()},
{file, Tmp},
{repair, false},
Expand Down Expand Up @@ -112,6 +111,7 @@ commit_write(OpaqueData) ->
ok ->
case disk_log:close(B#backup.file_desc) of
ok ->
file:delete(B#backup.file),
case file:rename(B#backup.tmp_file, B#backup.file) of
ok ->
{ok, B#backup.file};
Expand Down
6 changes: 5 additions & 1 deletion lib/mnesia/test/mnesia_evil_backup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ global_backup_checkpoint(Config) when is_list(Config) ->
?match(ok, mnesia:backup_checkpoint(cp_name, File)),
?match({error, _}, mnesia:backup_checkpoint(cp_name_nonexist, File)),
?match(ok, mnesia:backup_checkpoint(cp_name, File2, mnesia_backup)),
?match({error, _}, file:delete(File)),
?match(ok, file:delete(File)),
?match(ok, file:delete(File2)),
?verify_mnesia(Nodes, []).

Expand Down Expand Up @@ -761,7 +761,10 @@ sops_with_checkpoint(Config) when is_list(Config) ->
?match(ok, mnesia:dirty_write({Tab,8,-8})),

?match({atomic,ok}, mnesia:delete_table(Tab)),
?match(true, filelib:is_file(File2)),
?match({error,_}, mnesia:backup_checkpoint(cp2, File2)),
?match(true, filelib:is_file(File2)),

?match({'EXIT',_}, mnesia:dirty_write({Tab,9,-9})),

?match({atomic,_}, mnesia:restore(File1, [{default_op, recreate_tables}])),
Expand All @@ -772,6 +775,7 @@ sops_with_checkpoint(Config) when is_list(Config) ->
end
end,
[Test(N) || N <- mnesia:dirty_all_keys(Tab)],
ok = file:delete(File2),
?match({aborted,enoent}, mnesia:restore(File2, [{default_op, recreate_tables}])),

%% Mnesia crashes when deleting a table during backup
Expand Down

0 comments on commit 3168fcf

Please sign in to comment.