You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2024/07/23 02:48:45 UTC

(couchdb) branch main updated: Add passively closed client monitoring to search

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

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


The following commit(s) were added to refs/heads/main by this push:
     new 421412043 Add passively closed client monitoring to search
421412043 is described below

commit 4214120438750d57ba31baf77f63fff9ecc4c292
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Mon Jul 22 16:43:00 2024 -0400

    Add passively closed client monitoring to search
    
    We added client monitoring [1] for streaming fabric requests (_all_docs,
    _change, etc), but never added them to dreyfus since it's not using the streams
    abstraction.
    
    Add client monitoring to dreyfus but exporting a few internal functions from
    `fabric_stream`, otherwise the pattern is the same:
    
       * Start a client monitor process with the set of initial workers to monitor
         the coordinator and the client socket connection state.
       * In case of replacements, update the monitor with the newly spawned
         replacement workers.
       * On cleanup, call the previous `fabric_stream:cleanup/1` function, and also stop
         the monitor process.
    
    [1] https://github.com/apache/couchdb/commit/d5701f437183c3742aab5812e298d5bb80cb0c15
---
 src/dreyfus/src/dreyfus_fabric.erl        | 1 +
 src/dreyfus/src/dreyfus_fabric_group1.erl | 4 +++-
 src/dreyfus/src/dreyfus_fabric_group2.erl | 4 +++-
 src/dreyfus/src/dreyfus_fabric_search.erl | 4 +++-
 src/fabric/src/fabric_streams.erl         | 4 +++-
 5 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/dreyfus/src/dreyfus_fabric.erl b/src/dreyfus/src/dreyfus_fabric.erl
index 5689c1d4e..6603d05b5 100644
--- a/src/dreyfus/src/dreyfus_fabric.erl
+++ b/src/dreyfus/src/dreyfus_fabric.erl
@@ -136,6 +136,7 @@ handle_replacement(
             NewCounters = lists:foldl(
                 fun(Repl, CounterAcc) ->
                     NewCounter = start_replacement(StartFun, StartArgs, Repl),
+                    fabric_streams:add_worker_to_cleaner(self(), NewCounter),
                     fabric_dict:store(NewCounter, nil, CounterAcc)
                 end,
                 OldCounters,
diff --git a/src/dreyfus/src/dreyfus_fabric_group1.erl b/src/dreyfus/src/dreyfus_fabric_group1.erl
index 1edfd653f..8f26ec4ef 100644
--- a/src/dreyfus/src/dreyfus_fabric_group1.erl
+++ b/src/dreyfus/src/dreyfus_fabric_group1.erl
@@ -56,6 +56,8 @@ go(DbName, DDoc, IndexName, #index_query_args{} = QueryArgs) ->
         replacements = Replacements,
         ring_opts = RingOpts
     },
+    ClientReq = chttpd_util:mochiweb_client_req_get(),
+    fabric_streams:spawn_worker_cleaner(self(), Workers, ClientReq),
     try
         rexi_utils:recv(
             Workers,
@@ -67,7 +69,7 @@ go(DbName, DDoc, IndexName, #index_query_args{} = QueryArgs) ->
         )
     after
         rexi_monitor:stop(RexiMon),
-        fabric_util:cleanup(Workers)
+        fabric_streams:cleanup(Workers)
     end;
 go(DbName, DDoc, IndexName, OldArgs) ->
     go(DbName, DDoc, IndexName, dreyfus_util:upgrade(OldArgs)).
diff --git a/src/dreyfus/src/dreyfus_fabric_group2.erl b/src/dreyfus/src/dreyfus_fabric_group2.erl
index e962c7e4a..8385661a5 100644
--- a/src/dreyfus/src/dreyfus_fabric_group2.erl
+++ b/src/dreyfus/src/dreyfus_fabric_group2.erl
@@ -61,6 +61,8 @@ go(DbName, DDoc, IndexName, #index_query_args{} = QueryArgs) ->
         replacements = Replacements,
         ring_opts = RingOpts
     },
+    ClientReq = chttpd_util:mochiweb_client_req_get(),
+    fabric_streams:spawn_worker_cleaner(self(), Workers, ClientReq),
     try
         rexi_utils:recv(
             Workers,
@@ -72,7 +74,7 @@ go(DbName, DDoc, IndexName, #index_query_args{} = QueryArgs) ->
         )
     after
         rexi_monitor:stop(RexiMon),
-        fabric_util:cleanup(Workers)
+        fabric_streams:cleanup(Workers)
     end;
 go(DbName, DDoc, IndexName, OldArgs) ->
     go(DbName, DDoc, IndexName, dreyfus_util:upgrade(OldArgs)).
diff --git a/src/dreyfus/src/dreyfus_fabric_search.erl b/src/dreyfus/src/dreyfus_fabric_search.erl
index bb104892b..e19d1cd7f 100644
--- a/src/dreyfus/src/dreyfus_fabric_search.erl
+++ b/src/dreyfus/src/dreyfus_fabric_search.erl
@@ -113,6 +113,8 @@ go(DbName, DDoc, IndexName, QueryArgs, Counters, Bookmark, RingOpts) ->
         replacements = Replacements,
         ring_opts = RingOpts
     },
+    ClientReq = chttpd_util:mochiweb_client_req_get(),
+    fabric_streams:spawn_worker_cleaner(self(), Workers, ClientReq),
     RexiMon = fabric_util:create_monitors(Workers),
     try
         rexi_utils:recv(
@@ -144,7 +146,7 @@ go(DbName, DDoc, IndexName, QueryArgs, Counters, Bookmark, RingOpts) ->
             {error, Reason}
     after
         rexi_monitor:stop(RexiMon),
-        fabric_util:cleanup(Workers)
+        fabric_streams:cleanup(Workers)
     end.
 
 handle_message({ok, #top_docs{} = NewTopDocs}, Shard, State0) ->
diff --git a/src/fabric/src/fabric_streams.erl b/src/fabric/src/fabric_streams.erl
index 20ee98fd2..b7c6b3afc 100644
--- a/src/fabric/src/fabric_streams.erl
+++ b/src/fabric/src/fabric_streams.erl
@@ -17,7 +17,9 @@
     start/3,
     start/4,
     start/5,
-    cleanup/1
+    cleanup/1,
+    spawn_worker_cleaner/3,
+    add_worker_to_cleaner/2
 ]).
 
 -include_lib("fabric/include/fabric.hrl").