summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Lehnardt <jan@apache.org>2021-04-14 11:39:29 +0200
committerJan Lehnardt <jan@apache.org>2021-09-01 15:27:14 +0200
commitaabc7ae445c47ba57d15a4b6c6601bd0d818abb7 (patch)
tree1541c29aff0ab0a81bb7c5cfd07faa4b75efa6a6
parent9716f88ef164941cc165e3612c4ad7337de70f43 (diff)
downloadcouchdb-aabc7ae445c47ba57d15a4b6c6601bd0d818abb7.tar.gz
feat(couch_file): log file path when a file was truncated from under us
-rw-r--r--src/couch/src/couch_file.erl17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/couch/src/couch_file.erl b/src/couch/src/couch_file.erl
index b1e355518..2948d685b 100644
--- a/src/couch/src/couch_file.erl
+++ b/src/couch/src/couch_file.erl
@@ -711,10 +711,21 @@ read_raw_iolist_int(Fd, {Pos, _Size}, Len) -> % 0110 UPGRADE CODE
read_raw_iolist_int(Fd, Pos, Len);
read_raw_iolist_int(#file{fd = Fd} = File, Pos, Len) ->
{Pos, TotalBytes} = get_pread_locnum(File, Pos, Len),
- {ok, <<RawBin:TotalBytes/binary>>} = file:pread(Fd, Pos, TotalBytes),
- {remove_block_prefixes(Pos rem ?SIZE_BLOCK, RawBin), Pos + TotalBytes}.
-
+ case catch file:pread(Fd, Pos, TotalBytes) of
+ {ok, <<RawBin:TotalBytes/binary>>} ->
+ {remove_block_prefixes(Pos rem ?SIZE_BLOCK, RawBin), Pos + TotalBytes};
+ Else ->
+ % This clause matches when the file we are working with got truncated
+ % outside of CouchDB after we opened it. To find affected files, we
+ % need to log the file path.
+ %
+ % Technically, this should also go into read_multi_raw_iolists_int/2,
+ % but that doesn’t seem to be in use anywhere.
+ {_Fd, Filepath} = get(couch_file_fd),
+ throw({file_truncate_error, Else, Filepath})
+ end.
+% TODO: check if this is really unused
read_multi_raw_iolists_int(#file{fd = Fd} = File, PosLens) ->
LocNums = lists:map(fun({Pos, Len}) ->
get_pread_locnum(File, Pos, Len)