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/06/18 15:50:16 UTC

(couchdb) branch monitor-spawned-process-in-test created (now 19861051d)

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

rnewson pushed a change to branch monitor-spawned-process-in-test
in repository https://gitbox.apache.org/repos/asf/couchdb.git


      at 19861051d monitor spawned process for crash in test

This branch includes the following new commits:

     new 69b84113b use fabric to read/write _replicator docs if sws=true
     new 19861051d monitor spawned process for crash in test

The 2 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.



(couchdb) 01/02: use fabric to read/write _replicator docs if sws=true

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

rnewson pushed a commit to branch monitor-spawned-process-in-test
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 69b84113bae617c836589117f737be52361004dd
Author: Robert Newson <rn...@apache.org>
AuthorDate: Wed Jun 10 09:04:42 2026 +0100

    use fabric to read/write _replicator docs if sws=true
    
    closes https://github.com/apache/couchdb/issues/6029
---
 src/couch_replicator/src/couch_replicator.app.src  |  1 +
 src/couch_replicator/src/couch_replicator_docs.erl | 70 ++++++++++++++++++++++
 2 files changed, 71 insertions(+)

diff --git a/src/couch_replicator/src/couch_replicator.app.src b/src/couch_replicator/src/couch_replicator.app.src
index 4f68c5664..8739ea6de 100644
--- a/src/couch_replicator/src/couch_replicator.app.src
+++ b/src/couch_replicator/src/couch_replicator.app.src
@@ -26,6 +26,7 @@
         kernel,
         stdlib,
         couch_log,
+        fabric,
         mem3,
         config,
         couch,
diff --git a/src/couch_replicator/src/couch_replicator_docs.erl b/src/couch_replicator/src/couch_replicator_docs.erl
index 8f134aaab..7677c437d 100644
--- a/src/couch_replicator/src/couch_replicator_docs.erl
+++ b/src/couch_replicator/src/couch_replicator_docs.erl
@@ -196,7 +196,23 @@ update_rep_doc(RepDbName, #doc{body = {RepDocBody}} = RepDoc, KVs, _Try) ->
             save_rep_doc(RepDbName, RepDoc#doc{body = {NewRepDocBody}})
     end.
 
+open_rep_doc(<<"shards/", _/binary>> = DbName, DocId) ->
+    case serialize_worker_startup() of
+        true ->
+            open_rep_doc_fabric(DbName, DocId);
+        false ->
+            open_rep_doc_local(DbName, DocId)
+    end;
 open_rep_doc(DbName, DocId) ->
+    open_rep_doc_local(DbName, DocId).
+
+open_rep_doc_fabric(<<"shards/", _/binary>> = ShardDbName, DocId) ->
+    DbName = mem3:dbname(ShardDbName),
+    defer_call(fun() ->
+        fabric:open_doc(DbName, DocId, [?CTX])
+    end).
+
+open_rep_doc_local(DbName, DocId) ->
     ioq:maybe_set_io_priority({system, DbName}),
     case couch_db:open_int(DbName, [?CTX, sys_db]) of
         {ok, Db} ->
@@ -209,7 +225,33 @@ open_rep_doc(DbName, DocId) ->
             Else
     end.
 
+save_rep_doc(<<"shards/", _/binary>> = DbName, Doc) ->
+    case serialize_worker_startup() of
+        true ->
+            save_rep_doc_fabric(DbName, Doc);
+        false ->
+            save_rep_doc_local(DbName, Doc)
+    end;
 save_rep_doc(DbName, Doc) ->
+    save_rep_doc_local(DbName, Doc).
+
+save_rep_doc_fabric(<<"shards/", _/binary>> = ShardDbName, Doc) ->
+    DbName = mem3:dbname(ShardDbName),
+    defer_call(fun() ->
+        try
+            fabric:update_doc(DbName, Doc, [?CTX])
+        catch
+            % User can accidentally write a VDU which prevents _replicator from
+            % updating replication documents. Avoid crashing replicator and thus
+            % preventing all other replication jobs on the node from running.
+            throw:{forbidden, Reason} ->
+                Msg = "~p VDU function preventing doc update to ~s ~s ~p",
+                couch_log:error(Msg, [?MODULE, DbName, Doc#doc.id, Reason]),
+                {ok, forbidden}
+        end
+    end).
+
+save_rep_doc_local(DbName, Doc) ->
     ioq:maybe_set_io_priority({system, DbName}),
     {ok, Db} = couch_db:open_int(DbName, [?CTX, sys_db]),
     try
@@ -226,6 +268,34 @@ save_rep_doc(DbName, Doc) ->
         couch_db:close(Db)
     end.
 
+serialize_worker_startup() ->
+    config:get_boolean("fabric", "serialize_worker_startup", true).
+
+defer_call(Fun) ->
+    {Pid, Ref} = spawn_monitor(fun() ->
+        try Fun() of
+            Resp ->
+                exit({exit_ok, Resp})
+        catch
+            throw:Reason ->
+                exit({exit_throw, Reason});
+            error:Reason ->
+                exit({exit_error, Reason});
+            exit:Reason ->
+                exit({exit_exit, Reason})
+        end
+    end),
+    receive
+        {'DOWN', Ref, process, Pid, {exit_ok, Ret}} ->
+            Ret;
+        {'DOWN', Ref, process, Pid, {exit_throw, Reason}} ->
+            throw(Reason);
+        {'DOWN', Ref, process, Pid, {exit_error, Reason}} ->
+            error(Reason);
+        {'DOWN', Ref, process, Pid, {exit_exit, Reason}} ->
+            exit(Reason)
+    end.
+
 -spec before_doc_update(#doc{}, Db :: any(), couch_db:update_type()) -> #doc{}.
 before_doc_update(#doc{id = <<?DESIGN_DOC_PREFIX, _/binary>>} = Doc, _Db, _UpdateType) ->
     Doc;


(couchdb) 02/02: monitor spawned process for crash in test

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

rnewson pushed a commit to branch monitor-spawned-process-in-test
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 19861051de55510c28ced4fe67271cc072e4bdcd
Author: Robert Newson <rn...@apache.org>
AuthorDate: Thu Jun 18 16:49:54 2026 +0100

    monitor spawned process for crash in test
---
 .../test/eunit/couch_mrview_ddoc_updated_tests.erl           | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/couch_mrview/test/eunit/couch_mrview_ddoc_updated_tests.erl b/src/couch_mrview/test/eunit/couch_mrview_ddoc_updated_tests.erl
index 756434892..5f280b4de 100644
--- a/src/couch_mrview/test/eunit/couch_mrview_ddoc_updated_tests.erl
+++ b/src/couch_mrview/test/eunit/couch_mrview_ddoc_updated_tests.erl
@@ -104,7 +104,7 @@ check_indexing_stops_on_ddoc_change(Db) ->
 
         % spawn a process for query
         Self = self(),
-        QPid = spawn(fun() ->
+        {QPid, MRef} = spawn_monitor(fun() ->
             {ok, Result} = couch_mrview:query_view(
                 Db, <<"_design/bar">>, <<"baz">>, []
             ),
@@ -115,7 +115,15 @@ check_indexing_stops_on_ddoc_change(Db) ->
         {ok, _} = couch_db:update_doc(Db, DDocJson2, []),
         receive
             {QPid, Msg} ->
-                ?assertEqual(Msg, ddoc_updated)
+                ?assertEqual(Msg, ddoc_updated);
+            {'DOWN', MRef, process, QPid, Reason} ->
+                error(
+                    {assertion_failed, [
+                        {module, ?MODULE},
+                        {line, ?LINE},
+                        {reason, Reason}
+                    ]}
+                )
         after ?TIMEOUT ->
             error(
                 {assertion_failed, [