nickva commented on code in PR #5395:
URL: https://github.com/apache/couchdb/pull/5395#discussion_r1913389318
##########
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:
Good point Ilya, I'll change it
--
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]