You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ch...@apache.org on 2022/07/07 21:41:20 UTC

[couchdb] 03/03: Fix cherry-pick merge bugs

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

chewbranca pushed a commit to branch chewbranca-ioq-experiments-main-rebase
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit a19d6edc2301a4b94391cb5b6e56627b05f24de4
Author: Russell Branca <ch...@apache.org>
AuthorDate: Thu Jul 7 14:29:32 2022 -0700

    Fix cherry-pick merge bugs
---
 src/couch/src/couch_file.erl               | 75 ++++++++++++------------------
 src/couch_mrview/src/couch_mrview_util.erl |  1 -
 2 files changed, 30 insertions(+), 46 deletions(-)

diff --git a/src/couch/src/couch_file.erl b/src/couch/src/couch_file.erl
index 9d556da58..8fc5a65b5 100644
--- a/src/couch/src/couch_file.erl
+++ b/src/couch/src/couch_file.erl
@@ -72,32 +72,33 @@ open(Filepath, Options) ->
 
 open(Filepath, Options, IOQPid0) ->
     case gen_server:start_link(couch_file,
-            {Filepath, Options, self(), Ref = make_ref()}, []) of
-    {ok, Fd} ->
-        IOQPid = case IOQPid0 of
-            undefined ->
-                {ok, IOQPid1} = ioq_server2:start_link({by_shard, Filepath, Fd}),
-                IOQPid1;
-            IOQPid0 when is_pid(IOQPid0) ->
-                IOQPid0
-        end,
-        Tab = gen_server:call(Fd, get_cache_ref),
-        {ok, #ioq_file{fd=Fd, ioq=IOQPid, tab=Tab}};
-    ignore ->
-        % get the error
-        receive
-        {Ref, Pid, {error, Reason} = Error} ->
-            case process_info(self(), trap_exit) of
-            {trap_exit, true} -> receive {'EXIT', Pid, _} -> ok end;
-            {trap_exit, false} -> ok
-            end,
-            case {lists:member(nologifmissing, Options), Reason} of
-            {true, enoent} -> ok;
-            _ ->
-            couch_log:error("Could not open file ~s: ~s",
-                            [Filepath, file:format_error(Reason)])
-            end,
-            Error
+                               {Filepath, Options, self(), Ref = make_ref()}, []) of
+        {ok, Fd} ->
+            IOQPid = case IOQPid0 of
+                         undefined ->
+                             {ok, IOQPid1} = ioq_server2:start_link({by_shard, Filepath, Fd}),
+                             IOQPid1;
+                         IOQPid0 when is_pid(IOQPid0) ->
+                             IOQPid0
+                     end,
+            Tab = gen_server:call(Fd, get_cache_ref),
+            {ok, #ioq_file{fd=Fd, ioq=IOQPid, tab=Tab}};
+        ignore ->
+            % get the error
+            receive
+                {Ref, Pid, {error, Reason} = Error} ->
+                    case process_info(self(), trap_exit) of
+                        {trap_exit, true} -> receive {'EXIT', Pid, _} -> ok end;
+                        {trap_exit, false} -> ok
+                    end,
+                    case {lists:member(nologifmissing, Options), Reason} of
+                        {true, enoent} -> ok;
+                        _ ->
+                            couch_log:error("Could not open file ~s: ~s",
+                                            [Filepath, file:format_error(Reason)])
+                    end,
+                    Error
+            end
     end.
 
 set_db_pid(#ioq_file{fd=Fd}, Pid) ->
@@ -492,25 +493,9 @@ init({Filepath, Options, ReturnPid, Ref}) ->
                  Error ->
                      init_status_error(ReturnPid, Ref, Error)
             end;
-        false ->
-            % open in read mode first, so we don't create the file if it doesn't exist.
-            case file:open(Filepath, [read, raw]) of
-                {ok, Fd_Read} ->
-                    case file:open(Filepath, OpenOptions) of
-                        {ok, Fd} ->
-                            %% Save Fd in process dictionary for debugging purposes
-                            put(couch_file_fd, {Fd, Filepath}),
-                            ok = file:close(Fd_Read),
-                            maybe_track_open_os_files(Options),
-                            {ok, Eof} = file:position(Fd, eof),
-                            erlang:send_after(?INITIAL_WAIT, self(), maybe_close),
-                            {ok, #file{fd = Fd, eof = Eof, is_sys = IsSys, pread_limit = Limit}};
-                        Error ->
-                            init_status_error(ReturnPid, Ref, Error)
-                    end;
-                Error ->
-                    init_status_error(ReturnPid, Ref, Error)
-            end
+        Error ->
+            init_status_error(ReturnPid, Ref, Error)
+        end
     end.
 
 file_open_options(Options) ->
diff --git a/src/couch_mrview/src/couch_mrview_util.erl b/src/couch_mrview/src/couch_mrview_util.erl
index f6ccd062f..2ba96c353 100644
--- a/src/couch_mrview/src/couch_mrview_util.erl
+++ b/src/couch_mrview/src/couch_mrview_util.erl
@@ -316,7 +316,6 @@ init_state(Db, Fd, State, Header) ->
 
     {ShouldCommit, State#mrst{
         fd = Fd,
-        fd_monitor = erlang:monitor(process, Fd),
         fd_monitor=erlang:monitor(process, ioq:fd_pid(Fd)),
         update_seq = Seq,
         purge_seq = PurgeSeq,