You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2021/04/14 09:39:57 UTC
[couchdb] 01/01: feat(couch_file): log file path when a file was
truncated from under us
This is an automated email from the ASF dual-hosted git repository.
jan pushed a commit to branch feat/log-file-truncation
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 60910d4105d2a4741a89b75403bfb9bb4759e532
Author: Jan Lehnardt <ja...@apache.org>
AuthorDate: Wed Apr 14 11:39:29 2021 +0200
feat(couch_file): log file path when a file was truncated from under us
---
src/couch/src/couch_file.erl | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/src/couch/src/couch_file.erl b/src/couch/src/couch_file.erl
index b1e3555..2948d68 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)