@@ -396,47 +396,61 @@ iterator_read_chunk_with_read_ahead(Config) ->
396396 {ok , R } = osiris_log :init_offset_reader (0 , RConf ),
397397 Tests =
398398 [
399- fun (#{w := W0 , r := R0 }) ->
400- % % first chunk, there won't be any data size hints in the reader
399+ fun (write , #{w := W0 }) ->
401400 EntriesRev = [<<" hi" >>, <<" ho" >>],
402401 {_ , W1 } = write_committed (EntriesRev , W0 ),
402+ W1 ;
403+ (read , #{r := R0 , tracer := T }) ->
404+ % % first chunk, there won't be any data size hints in the reader
403405 {ok , H , I0 , R1 } = osiris_log :chunk_iterator (R0 ),
404406 {{_ , <<" ho" >>}, I1 } = osiris_log :iterator_next (I0 ),
405407 {{_ , <<" hi" >>}, I2 } = osiris_log :iterator_next (I1 ),
406408 ? assertMatch (end_of_chunk , osiris_log :iterator_next (I2 )),
407- {H , W1 , R1 }
409+ ? assertEqual (2 , length (osiris_tracer :calls (T ))),
410+ {H , R1 }
408411 end ,
409- fun (#{w := W0 , r : = R0 }) ->
412+ fun (write , #{w := W0 }) ->
410413 % % this one will be read ahead
411414 EntriesRev = [<<" foo" >>, <<" bar" >>],
412415 {_ , W1 } = write_committed (EntriesRev , W0 ),
416+ W1 ;
417+ (read , #{r := R0 , tracer := T }) ->
413418 {ok , H , I0 , R1 } = osiris_log :chunk_iterator (R0 ),
414419 {{_ , <<" bar" >>}, I1 } = osiris_log :iterator_next (I0 ),
415420 {{_ , <<" foo" >>}, I2 } = osiris_log :iterator_next (I1 ),
416421 ? assertMatch (end_of_chunk , osiris_log :iterator_next (I2 )),
417- {H , W1 , R1 }
422+ ? assertEqual (0 , length (osiris_tracer :calls (T ))),
423+ {H , R1 }
418424 end ,
419- fun (#{w := W0 , r : = R0 }) ->
425+ fun (write , #{w := W0 }) ->
420426 % % this one will be read ahead
421- E1 = rand : bytes ( RAL - 100 ),
427+ E1 = binary : copy (<< " b " >>, RAL - 200 ),
422428 EntriesRev = [E1 , <<" aaa" >>],
423429 {_ , W1 } = write_committed (EntriesRev , W0 ),
430+ W1 ;
431+ (read , #{r := R0 , tracer := T }) ->
432+ E1 = binary :copy (<<" b" >>, RAL - 200 ),
424433 {ok , H , I0 , R1 } = osiris_log :chunk_iterator (R0 ),
425434 {{_ , <<" aaa" >>}, I1 } = osiris_log :iterator_next (I0 ),
426435 {{_ , E1 }, I2 } = osiris_log :iterator_next (I1 ),
427436 ? assertMatch (end_of_chunk , osiris_log :iterator_next (I2 )),
428- {H , W1 , R1 }
437+ ? assertEqual (0 , length (osiris_tracer :calls (T ))),
438+ {H , R1 }
429439 end ,
430- fun (#{w := W0 , r : = R0 }) ->
440+ fun (write , #{w := W0 }) ->
431441 % % this one is too big to be read ahead
432- E1 = rand : bytes ( RAL * 2 ),
442+ E1 = binary : copy (<< " b " >>, RAL * 2 ),
433443 EntriesRev = [E1 , <<" aaa" >>],
434444 {_ , W1 } = write_committed (EntriesRev , W0 ),
445+ W1 ;
446+ (read , #{r := R0 , tracer := T }) ->
447+ E1 = binary :copy (<<" b" >>, RAL * 2 ),
435448 {ok , H , I0 , R1 } = osiris_log :chunk_iterator (R0 ),
436449 {{_ , <<" aaa" >>}, I1 } = osiris_log :iterator_next (I0 ),
437450 {{_ , E1 }, I2 } = osiris_log :iterator_next (I1 ),
438451 ? assertMatch (end_of_chunk , osiris_log :iterator_next (I2 )),
439- {H , W1 , R1 }
452+ ? assertEqual (2 , length (osiris_tracer :calls (T ))),
453+ {H , R1 }
440454 end
441455 ],
442456
@@ -2172,11 +2186,18 @@ init_reader(data, Conf) ->
21722186 osiris_log :init_data_reader ({0 , empty }, Conf ).
21732187
21742188run_read_ahead_tests (Tests , RType , FSize , Wr0 , Rd0 ) ->
2175- lists :foldl (fun (F , Acc ) ->
2176- {H , W , R0 } = F (Acc ),
2177- R1 = update_read (H , R0 ),
2178- #{w => W , r => R1 , rtype => RType , fsize => FSize }
2179- end , #{w => Wr0 , r => Rd0 , rtype => RType , fsize => FSize }, Tests ).
2189+ W = lists :foldl (fun (F , Acc ) ->
2190+ W = F (write , Acc ),
2191+ #{w => W }
2192+ end , #{w => Wr0 }, Tests ),
2193+ R = lists :foldl (fun (F , Acc ) ->
2194+ Tracer = osiris_tracer :start ({file , pread , '_' }),
2195+ {_ , R0 } = F (read , Acc #{tracer => Tracer }),
2196+ osiris_tracer :stop (Tracer ),
2197+ % R1 = update_read(H, R0),
2198+ #{r => R0 , rtype => RType , fsize => FSize }
2199+ end , #{r => Rd0 , rtype => RType , fsize => FSize }, Tests ),
2200+ maps :merge (W , R ).
21802201
21812202- spec update_read (map (), osiris_log :state ()) -> osiris_log :state ().
21822203update_read (#{chunk_id := ChId ,
0 commit comments