This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch couch_file-perf-regression-fix
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit e4889be1a76e2cb6e95ab6d570240a37e5ffd827
Author: Robert Newson <[email protected]>
AuthorDate: Thu Sep 10 17:28:03 2026 +0100

    add optional eof validation in couch_file
---
 src/couch/src/couch_file.erl | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/couch/src/couch_file.erl b/src/couch/src/couch_file.erl
index 2d0920f7e..9b7dbb159 100644
--- a/src/couch/src/couch_file.erl
+++ b/src/couch/src/couch_file.erl
@@ -625,6 +625,12 @@ eof(#file{fd = Fd}) ->
     file:position(Fd, eof).
 
 append_bins(#file{fd = Fd, eof = Pos} = File, Bins) ->
+    case config:get_boolean("couch_file", "append_bin_eof_check", false) of
+        true ->
+            validate_eof(File);
+        false ->
+            ok
+    end,
     {BlockResps, FinalPos} = lists:mapfoldl(
         fun(Bin, PosAcc) ->
             Blocks = make_blocks(PosAcc rem ?SIZE_BLOCK, Bin),
@@ -771,6 +777,12 @@ find_newest_header(Fd, [{Location, Size} | LocationSizes]) 
->
     end.
 
 handle_write_header(Bin, #file{fd = Fd, eof = Pos} = File) ->
+    case config:get_boolean("couch_file", "write_header_eof_check", false) of
+        true ->
+            validate_eof(File);
+        false ->
+            ok
+    end,
     BinSize = byte_size(Bin),
     case Pos rem ?SIZE_BLOCK of
         0 -> Padding = <<>>;
@@ -1026,6 +1038,15 @@ dup(#file{fd = Fd} = File) ->
             File
     end.
 
+validate_eof(#file{} = File) ->
+    {ok, ActualPos} = file:position(File#file.fd, eof),
+    if
+        File#file.eof /= ActualPos ->
+            throw_stop({eof_sync, ActualPos, File#file.eof}, File);
+        true ->
+            ok
+    end.
+
 -ifdef(TEST).
 -include_lib("couch/include/couch_eunit.hrl").
 

Reply via email to