Skip to content

Commit 9a0ece8

Browse files
Refactor osiris_log:stream_offset_samples so that
a) it leverages idx_skip_search b) it adds a callback function to idx_skip_search that is able to find several offsets in one scan
1 parent f3d250c commit 9a0ece8

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/osiris_log.erl

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,6 @@
122122

123123
-define(SKIP_SEARCH_JUMP, 2048).
124124
-define(DEFAULT_READ_AHEAD_LIMIT, 4096).
125-
%% Block size for index scan in fold_index_files_closest (records per read)
126-
-define(INDEX_READ_BLOCK_RECORDS, 1024).
127-
-define(INDEX_READ_BLOCK_BYTES, (?INDEX_READ_BLOCK_RECORDS * ?INDEX_RECORD_SIZE_B)).
128125

129126
%% Specification of the Log format.
130127
%%
@@ -3522,7 +3519,8 @@ write_in_chunks(_, _, _, W) ->
35223519
%% Fractions is a list of floats in [0.0, 1.0]: 0.0 = first, 1.0 = last;
35233520
%% values in between are linear (e.g. 0.5 = midpoint by chunk id).
35243521
%% Returns {ok, [ {float(), offset(), timestamp()} ]} (one 3-tuple per requested fraction),
3525-
%% or {error, empty}. Fractions are clamped to [0.0, 1.0].
3522+
%% or {error, empty}.
3523+
%% Fractions below 0.0 are normalized to 0.0; fractions above 1.0 are normalized to 1.0.
35263524
-spec stream_offset_samples(file:filename_all() | config(), [float()]) ->
35273525
{ok, [{float(), offset(), osiris:timestamp()}]} | {error, empty}.
35283526
stream_offset_samples(_DirOrConfig, []) ->
@@ -3539,7 +3537,7 @@ stream_offset_samples(DirOrConfig, Fractions0) ->
35393537

35403538
-spec stream_offset_samples_with_index(Fractions :: [float()], IdxFiles :: list()) ->
35413539
{ok, [{float(), offset(), osiris:timestamp()}]} | {error, empty}.
3542-
%% Pre: IdxFiles is non-empty.
3540+
35433541
stream_offset_samples_with_index(Fractions, IdxFiles) ->
35443542
case first_and_last_seginfos0(IdxFiles) of
35453543
none ->
@@ -3575,7 +3573,6 @@ normalize_fraction(F) when F =< 0.0 -> 0.0;
35753573
normalize_fraction(F) when F >= 1.0 -> 1.0;
35763574
normalize_fraction(F) -> F.
35773575

3578-
%% Returns [{float(), offset(), timestamp()}]. Order: first (if requested), middle samples, last (if requested).
35793576
assemble_offset_samples(Fractions, First, Last, MiddleSamples) ->
35803577
FirstPart = case lists:member(0.0, Fractions) of
35813578
true -> [First];
@@ -3592,7 +3589,8 @@ target_chunk_id(FirstChId, Range, 1.0) -> FirstChId + Range;
35923589
target_chunk_id(FirstChId, Range, F) ->
35933590
FirstChId + round((Range * F)).
35943591

3595-
%% Multi-target version: one idx_skip_search pass over the index.
3592+
%% multi_offset_sample_search_fun: one idx_skip_search pass over the index to gather
3593+
%% as many offset samples in Pending list as exists in one index file.
35963594
%% Acc = {Pending, Results, LastChunk}.
35973595
%% Pending = [{float(), offset()}] remaining targets.
35983596
%% Results = [{float(), offset(), timestamp()}]. LastChunk = undefined | {ChunkId, Ts}.
@@ -3682,8 +3680,6 @@ find_offsets_on_index_file(TargetOffsets, IdxFile, AccResults) ->
36823680
end.
36833681

36843682

3685-
3686-
36873683
-ifdef(TEST).
36883684
-include_lib("eunit/include/eunit.hrl").
36893685

test/osiris_log_SUITE.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ all_tests() ->
114114
stream_offset_unordered_fraction_samples,
115115
stream_offset_subset_samples_only,
116116
stream_offset_unnormalized_samples,
117-
stream_offset_samples_multi_segment_two_in_second_one_in_fourth
117+
stream_offset_with_samples_over_multi_segments
118118
].
119119

120120
groups() ->

0 commit comments

Comments
 (0)