iilyak commented on code in PR #5395:
URL: https://github.com/apache/couchdb/pull/5395#discussion_r1913239794
##########
src/couch/src/couch_file.erl:
##########
@@ -692,35 +690,45 @@ find_newest_header(Fd, [{Location, Size} |
LocationSizes]) ->
find_newest_header(Fd, LocationSizes)
end.
-read_multi_raw_iolists_int(#file{fd = Fd} = File, PosLens) ->
+read_multi_raw_iolists_int(#file{fd = Fd, eof = Eof} = File, PosLens) ->
MapFun = fun({Pos, Len}) -> get_pread_locnum(File, Pos, Len) end,
LocNums = lists:map(MapFun, PosLens),
- {ok, Bins} = file:pread(Fd, LocNums),
ZipFun = fun({Pos, TotalBytes}, Bin) ->
- <<RawBin:TotalBytes/binary>> = Bin,
- {remove_block_prefixes(Pos rem ?SIZE_BLOCK, RawBin), Pos + TotalBytes}
+ case is_binary(Bin) andalso byte_size(Bin) == TotalBytes of
+ true ->
+ {remove_block_prefixes(Pos rem ?SIZE_BLOCK, Bin), Pos +
TotalBytes};
+ false ->
+ couch_stats:increment_counter([pread, exceed_eof]),
+ {ok, CurEof} = file:position(File#file.fd, eof),
+ {_Fd, Filepath} = get(couch_file_fd),
+ throw_stop({read_beyond_eof, Filepath, Pos, TotalBytes, Eof,
CurEof}, File)
+ end
end,
- lists:zipwith(ZipFun, LocNums, Bins).
+ case file:pread(Fd, LocNums) of
+ {ok, Bins} ->
+ lists:zipwith(ZipFun, LocNums, Bins);
+ {error, Error} ->
+ {_Fd, Filepath} = get(couch_file_fd),
+ throw_stop({pread, Error, Filepath, hd(LocNums)}, File)
Review Comment:
A nitpick, in all other error types in the PR the `Filepath` is a second
element of the tuple. Which makes it easier to extract in logs analytics
pipeline. However this particular error has it as third element, which makes it
special.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]