You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2026/09/26 16:18:28 UTC

(couchdb) branch flock updated (1f8817b10 -> 114d0ff29)

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

rnewson pushed a change to branch flock
in repository https://gitbox.apache.org/repos/asf/couchdb.git


 discard 1f8817b10 Take an exclusive lock on all couch_cfiles
     new 114d0ff29 Take an exclusive lock on all couch_cfiles

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (1f8817b10)
            \
             N -- N -- N   refs/heads/flock (114d0ff29)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/couch/src/couch_file.erl | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)


(couchdb) 01/01: Take an exclusive lock on all couch_cfiles

Posted by rn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch flock
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 114d0ff29246ca19e4dbc8f8d3ae17a3b71e15ad
Author: Robert Newson <rn...@apache.org>
AuthorDate: Sat Sep 26 16:42:26 2026 +0100

    Take an exclusive lock on all couch_cfiles
    
    This allows external processes to avoid modifying a file that couchdb
    currently has open (by also attempting to take an exclusive file lock).
---
 src/couch/src/couch_file.erl | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/src/couch/src/couch_file.erl b/src/couch/src/couch_file.erl
index 1a69fa017..36692aa24 100644
--- a/src/couch/src/couch_file.erl
+++ b/src/couch/src/couch_file.erl
@@ -24,6 +24,7 @@
 -define(WRITE_XXHASH_CHECKSUMS_DEFAULT, true).
 
 -define(USE_CFILE_DEFAULT, true).
+-define(USE_CFILE_FLOCK_DEFAULT, true).
 -define(CFILE_SKIP_IOQ_DEFAULT, false).
 -define(CFILE_HANDLE, cfile_handle).
 
@@ -474,7 +475,7 @@ init({Filepath, Options, ReturnPid, Ref}) ->
                                     ok = fsync(Fd),
                                     maybe_track_open_os_files(Options),
                                     erlang:send_after(?INITIAL_WAIT, self(), maybe_close),
-                                    {ok, dup(File#file{fd = Fd})};
+                                    maybe_cfile(File#file{fd = Fd}, ReturnPid, Ref);
                                 false ->
                                     ok = file:close(Fd),
                                     init_status_error(ReturnPid, Ref, {error, eexist})
@@ -482,7 +483,7 @@ init({Filepath, Options, ReturnPid, Ref}) ->
                         false ->
                             maybe_track_open_os_files(Options),
                             erlang:send_after(?INITIAL_WAIT, self(), maybe_close),
-                            {ok, dup(File#file{fd = Fd})}
+                            maybe_cfile(File#file{fd = Fd}, ReturnPid, Ref)
                     end;
                 Error ->
                     init_status_error(ReturnPid, Ref, Error)
@@ -499,7 +500,7 @@ init({Filepath, Options, ReturnPid, Ref}) ->
                             maybe_track_open_os_files(Options),
                             {ok, Eof} = file:position(Fd, eof),
                             erlang:send_after(?INITIAL_WAIT, self(), maybe_close),
-                            {ok, dup(File#file{fd = Fd, eof = Eof})};
+                            maybe_cfile(File#file{fd = Fd, eof = Eof}, ReturnPid, Ref);
                         Error ->
                             init_status_error(ReturnPid, Ref, Error)
                     end;
@@ -1007,7 +1008,7 @@ get_cfile(Pid) when is_pid(Pid) ->
             end
     end.
 
-dup(#file{fd = Fd} = File) ->
+maybe_cfile(#file{fd = Fd} = File, ReturnPid, Ref) ->
     case config:get_boolean("couchdb", "use_cfile", ?USE_CFILE_DEFAULT) of
         true ->
             case couch_cfile:dup(Fd) of
@@ -1019,12 +1020,24 @@ dup(#file{fd = Fd} = File) ->
                     put(couch_file_fd, {CFd, CFile#file.filepath}),
                     % Use an effective infinity for eof max limit for now
                     put(?CFILE_HANDLE, CFile#file{eof = 1 bsl 60}),
-                    CFile;
-                {error, _Error} ->
-                    File
+                    case
+                        config:get_boolean("couchdb", "use_cfile_flock", ?USE_CFILE_FLOCK_DEFAULT)
+                    of
+                        true ->
+                            case couch_cfile:flock(CFd, exclusive) of
+                                ok ->
+                                    {ok, CFile};
+                                {error, Reason} ->
+                                    init_status_error(ReturnPid, Ref, {error, Reason})
+                            end;
+                        false ->
+                            {ok, CFile}
+                    end;
+                {error, Reason} ->
+                    init_status_error(ReturnPid, Ref, {error, Reason})
             end;
         false ->
-            File
+            {ok, File}
     end.
 
 validate_eof(#file{} = File) ->