Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/ra_file.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

-include("ra.hrl").

-define(HANDLE_EAGAIN(Op),
-define(RETRY_ON_ERROR(Op),
case Op of
{error, eagain} ->
?DEBUG("EAGAIN during file operation, retrying once in 10ms...", []),
timer:sleep(10),
{error, E} when E =:= eagain orelse E =:= eacces ->
?DEBUG("Error `~p` during file operation, retrying once in 20ms...", [E]),
timer:sleep(20),
case Op of
{error, eagain} = Err ->
?DEBUG("EAGAIN again during file operation", []),
?DEBUG("Error `~p` again during file operation", [E]),
Err;
Res ->
Res
Expand All @@ -26,8 +26,12 @@
end).

-export([
sync/1
sync/1,
rename/2
]).

sync(Fd) ->
?HANDLE_EAGAIN(file:sync(Fd)).
?RETRY_ON_ERROR(file:sync(Fd)).

rename(Src, Dst) ->
?RETRY_ON_ERROR(prim_file:rename(Src, Dst)).
2 changes: 1 addition & 1 deletion src/ra_snapshot.erl
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ promote_checkpoint(PromotionIdx,
%% sync the checkpoint before promoting it
%% into a snapshot.
ok = Mod:sync(Checkpoint),
ok = prim_file:rename(Checkpoint, Snapshot),
ok = ra_file:rename(Checkpoint, Snapshot),
Self ! {ra_log_event,
{snapshot_written,
{Idx, Term}, snapshot}}
Expand Down