Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a new file handle to recover tracking. #157

Merged
merged 1 commit into from
Mar 21, 2024
Merged
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
16 changes: 12 additions & 4 deletions src/osiris_log.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2727,14 +2727,22 @@ part(Len, [B | L]) when Len > 0 ->

-spec recover_tracking(state()) ->
osiris_tracking:state().
recover_tracking(#?MODULE{cfg = #cfg{tracking_config = TrkConfig},
fd = Fd}) ->
recover_tracking(#?MODULE{cfg = #cfg{directory = Dir,
tracking_config = TrkConfig},
current_file = File}) ->
%% we need to open a new file handle here as we cannot use the one that is
%% being used for appending to the segment as pread _may_ move the file
%% position on some systems (such as windows)
{ok, Fd} = open(filename:join(Dir, File), [read, raw, binary]),
_ = file:advise(Fd, 0, 0, random),
%% TODO: if the first chunk in the segment isn't a tracking snapshot and
%% there are prior segments we could scan at least two segments increasing
%% the chance of encountering a snapshot and thus ensure we don't miss any
%% tracking entries
Trk = osiris_tracking:init(undefined, TrkConfig),
recover_tracking(Fd, Trk, ?LOG_HEADER_SIZE).
Trk0 = osiris_tracking:init(undefined, TrkConfig),
Trk = recover_tracking(Fd, Trk0, ?LOG_HEADER_SIZE),
_ = file:close(Fd),
Trk.

recover_tracking(Fd, Trk0, Pos0) ->
case file:pread(Fd, Pos0, ?HEADER_SIZE_B) of
Expand Down
Loading