From 9c98070cc91bd4064ab158f60b7356fb21459acf Mon Sep 17 00:00:00 2001 From: ILYA Khlopotov Date: Thu, 3 Nov 2016 09:05:00 -0700 Subject: [PATCH] Include file_path on errors from couch_file Add PathFile as part of a reason for following errors: - read_beyond_eof - exceed_pread_limit exceptions --- src/couch_file.erl | 14 ++++++++------ test/couch_file_tests.erl | 6 ++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/couch_file.erl b/src/couch_file.erl index e7d94136..19e59985 100644 --- a/src/couch_file.erl +++ b/src/couch_file.erl @@ -428,10 +428,10 @@ handle_call({pread_iolist, Pos}, _From, File) -> % up to 8Kbs of read ahead read_raw_iolist_int(File, Pos, ?READ_AHEAD - (Pos rem ?SIZE_BLOCK)) catch - throw:read_beyond_eof -> - throw(read_beyond_eof); - throw:{exceed_pread_limit, Limit} -> - throw({exceed_pread_limit, Limit}); + throw:{read_beyond_eof, _} = Reason -> + throw(Reason); + throw:{exceed_pread_limit, _, _} = Reason -> + throw(Reason); _:_ -> read_raw_iolist_int(File, Pos, 4) end, @@ -625,10 +625,12 @@ read_raw_iolist_int(#file{fd = Fd, pread_limit = Limit} = F, Pos, Len) -> case Pos + TotalBytes of Size when Size > F#file.eof + ?READ_AHEAD -> couch_stats:increment_counter([pread, exceed_eof]), - throw(read_beyond_eof); + {_Fd, Filepath} = get(couch_file_fd), + throw({read_beyond_eof, Filepath}); Size when Size > Limit -> couch_stats:increment_counter([pread, exceed_limit]), - throw({exceed_pread_limit, Limit}); + {_Fd, Filepath} = get(couch_file_fd), + throw({exceed_pread_limit, Filepath, Limit}); Size -> {ok, <>} = file:pread(Fd, Pos, TotalBytes), {remove_block_prefixes(BlockOffset, RawBin), Size} diff --git a/test/couch_file_tests.erl b/test/couch_file_tests.erl index 497999e2..c16be16c 100644 --- a/test/couch_file_tests.erl +++ b/test/couch_file_tests.erl @@ -139,7 +139,8 @@ should_not_read_beyond_eof(Fd) -> ok = file:pwrite(Io, Pos, <<0:1/integer, DoubleBin:31/integer>>), file:close(Io), unlink(Fd), - ExpectedError = {badmatch, {'EXIT', {bad_return_value, read_beyond_eof}}}, + ExpectedError = {badmatch, {'EXIT', {bad_return_value, + {read_beyond_eof, Filepath}}}}, ?_assertError(ExpectedError, couch_file:pread_binary(Fd, Pos)). should_truncate(Fd) -> @@ -175,11 +176,12 @@ pread_limit_test_() -> }. should_not_read_more_than_pread_limit(Fd) -> + {_, Filepath} = couch_file:process_info(Fd), BigBin = list_to_binary(lists:duplicate(100000, 0)), {ok, Pos, _Size} = couch_file:append_binary(Fd, BigBin), unlink(Fd), ExpectedError = {badmatch, {'EXIT', {bad_return_value, - {exceed_pread_limit, 50000}}}}, + {exceed_pread_limit, Filepath, 50000}}}}, ?_assertError(ExpectedError, couch_file:pread_binary(Fd, Pos)).