Skip to content

Commit

Permalink
tweak random advise
Browse files Browse the repository at this point in the history
  • Loading branch information
kjnilsson committed Dec 13, 2024
1 parent f2fdf7b commit 179ff36
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/ra_log_segment.erl
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,23 @@ open(Filename, Options) ->
end.

process_file(true, Mode, Filename, Fd, Options) ->
AccessPattern = maps:get(access_pattern, Options, random),
if AccessPattern == random andalso
Mode == read ->
%% advise for random access for any data beyond our best guess
%% index size, readers could pass `max_count` in the config to
%% ensure this is correct
ConfMaxCount = maps:get(max_count, Options, ?SEGMENT_MAX_ENTRIES),
Offset = ?HEADER_SIZE + (ConfMaxCount * ?INDEX_RECORD_SIZE_V2),
ok = file:advise(Fd, Offset, 0, random);
true ->
ok
end,
case read_header(Fd) of
{ok, Version, MaxCount} ->
MaxPending = maps:get(max_pending, Options, ?SEGMENT_MAX_PENDING),
IndexRecordSize = index_record_size(Version),
IndexSize = MaxCount * IndexRecordSize,
AccessPattern = maps:get(access_pattern, Options, random),
if AccessPattern == random ->
ok = file:advise(Fd, 0, 0, random);
true ->
ok
end,
{NumIndexRecords, DataOffset, Range, Index} =
recover_index(Fd, Version, MaxCount),
IndexOffset = ?HEADER_SIZE + NumIndexRecords * IndexRecordSize,
Expand Down

0 comments on commit 179ff36

Please sign in to comment.