You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ji...@apache.org on 2025/09/08 18:13:41 UTC

(couchdb) branch increase-timeout-for-check_services created (now bcff5f1d5)

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

jiahuili430 pushed a change to branch increase-timeout-for-check_services
in repository https://gitbox.apache.org/repos/asf/couchdb.git


      at bcff5f1d5 Dynamically set the `Timeout` to check the search services

This branch includes the following new commits:

     new bcff5f1d5 Dynamically set the `Timeout` to check the search services

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.



(couchdb) 01/01: Dynamically set the `Timeout` to check the search services

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

jiahuili430 pushed a commit to branch increase-timeout-for-check_services
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit bcff5f1d5c0ff767f41fafe77368f827d03d4d45
Author: Jiahui Li <li...@gmail.com>
AuthorDate: Mon Sep 8 12:56:28 2025 -0500

    Dynamically set the `Timeout` to check the search services
    
    Checking whether the search service is active depends on the
    server workload. If the server is busy, 200 milliseconds will
    always trigger a `timeout`. Therefore, increase the default
    value to 2 seconds to avoid false positives.
    
    Also added a `Timeout` parameter to allow users to customize it.
---
 src/dreyfus/src/clouseau_rpc.erl | 37 +++++++++++++++++++++++++++----------
 1 file changed, 27 insertions(+), 10 deletions(-)

diff --git a/src/dreyfus/src/clouseau_rpc.erl b/src/dreyfus/src/clouseau_rpc.erl
index 77c304c95..4cf68d624 100644
--- a/src/dreyfus/src/clouseau_rpc.erl
+++ b/src/dreyfus/src/clouseau_rpc.erl
@@ -22,7 +22,8 @@
 -export([delete/2, update/3, cleanup/1, cleanup/2, rename/1]).
 -export([analyze/2, version/0, disk_size/1]).
 -export([set_purge_seq/2, get_purge_seq/1, get_root_dir/0]).
--export([connected/0, check_service/1, check_services/0]).
+-export([connected/0]).
+-export([check_service/1, check_service/2, check_services/0, check_services/1]).
 
 %% string represented as binary
 -type string_as_binary(_Value) :: nonempty_binary().
@@ -65,7 +66,7 @@
         | {string_as_binary(stopwords), [field_name()]}
     ].
 
--define(TIMEOUT, 200).
+-define(SEARCH_SERVICE_TIMEOUT, 2000).
 
 -spec open_index(Peer :: pid(), Path :: shard(), Analyzer :: analyzer()) ->
     {ok, indexer_pid()} | error().
@@ -348,11 +349,20 @@ clouseau_services(_MajorVsn) ->
 is_valid(Service) when is_atom(Service) ->
     lists:member(Service, clouseau_services(clouseau_major_vsn())).
 
--spec check_service(Service) -> {service(), liveness_status()} | throw({atom(), binary()}) when
-    Service :: service().
-check_service(Service) when is_list(Service) ->
-    check_service(list_to_atom(Service));
-check_service(Service) when is_atom(Service) ->
+-spec check_service(Service) -> Result when
+    Service :: service(),
+    Result :: {service(), liveness_status()} | throw({atom(), binary()}).
+check_service(Service) ->
+    check_service(Service, ?SEARCH_SERVICE_TIMEOUT).
+
+-spec check_service(Service, Timeout) ->
+    {service(), liveness_status()} | throw({atom(), binary()})
+when
+    Service :: service(),
+    Timeout :: timeout().
+check_service(Service, Timeout) when is_list(Service) ->
+    check_service(list_to_atom(Service), Timeout);
+check_service(Service, Timeout) when is_atom(Service) ->
     case is_valid(Service) of
         true ->
             Ref = make_ref(),
@@ -360,7 +370,7 @@ check_service(Service) when is_atom(Service) ->
             receive
                 {pong, Ref} ->
                     {Service, alive}
-            after ?TIMEOUT ->
+            after Timeout ->
                 {Service, timeout}
             end;
         false ->
@@ -368,12 +378,19 @@ check_service(Service) when is_atom(Service) ->
             throw({not_found, <<"no such service: ", NoService/binary>>})
     end.
 
--spec check_services() -> [{service(), liveness_status()}] | throw({atom(), binary()}).
+-spec check_services() -> Result when
+    Result :: [{service(), liveness_status()}] | throw({atom(), binary()}).
 check_services() ->
+    check_services(?SEARCH_SERVICE_TIMEOUT).
+
+-spec check_services(Timeout) -> Result when
+    Timeout :: timeout(),
+    Result :: [{service(), liveness_status()}] | throw({atom(), binary()}).
+check_services(Timeout) ->
     case connected() of
         true ->
             Services = clouseau_services(clouseau_major_vsn()),
-            [check_service(S) || S <- Services];
+            [check_service(S, Timeout) || S <- Services];
         false ->
             throw({noconnection, <<"Clouseau node is not connected.">>})
     end.