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 2023/04/04 09:35:49 UTC

[couchdb] branch dreyfus-await-time updated (8f939ff68 -> 931c5f48a)

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

rnewson pushed a change to branch dreyfus-await-time
in repository https://gitbox.apache.org/repos/asf/couchdb.git


 discard 8f939ff68 WIP send await time in response header - dreyfus
     new 931c5f48a WIP send await time in response header - dreyfus

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   (8f939ff68)
            \
             N -- N -- N   refs/heads/dreyfus-await-time (931c5f48a)

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/dreyfus/src/dreyfus_httpd.erl | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)


[couchdb] 01/01: WIP send await time in response header - dreyfus

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

rnewson pushed a commit to branch dreyfus-await-time
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 931c5f48ae87bec0ba16e37e9d2b0ea8afb27062
Author: Robert Newson <rn...@apache.org>
AuthorDate: Tue Apr 4 10:32:52 2023 +0100

    WIP send await time in response header - dreyfus
---
 src/dreyfus/src/dreyfus_fabric_search.erl | 20 ++++++++++++++++----
 src/dreyfus/src/dreyfus_httpd.erl         | 22 +++++++++++++++-------
 src/dreyfus/src/dreyfus_rpc.erl           |  3 +++
 3 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/src/dreyfus/src/dreyfus_fabric_search.erl b/src/dreyfus/src/dreyfus_fabric_search.erl
index 7e78e5fc3..77a19d44a 100644
--- a/src/dreyfus/src/dreyfus_fabric_search.erl
+++ b/src/dreyfus/src/dreyfus_fabric_search.erl
@@ -27,7 +27,8 @@
     counters,
     start_args,
     replacements,
-    ring_opts
+    ring_opts,
+    await_time = 0
 }).
 
 go(DbName, GroupId, IndexName, QueryArgs) when is_binary(GroupId) ->
@@ -125,7 +126,7 @@ go(DbName, DDoc, IndexName, QueryArgs, Counters, Bookmark, RingOpts) ->
         )
     of
         {ok, Result} ->
-            #state{top_docs = TopDocs} = Result,
+            #state{top_docs = TopDocs, await_time = AwaitTime} = Result,
             #top_docs{
                 total_hits = TotalHits,
                 hits = Hits,
@@ -134,11 +135,11 @@ go(DbName, DDoc, IndexName, QueryArgs, Counters, Bookmark, RingOpts) ->
             } = TopDocs,
             case RawBookmark of
                 true ->
-                    {ok, Bookmark, TotalHits, Hits, Counts, Ranges};
+                    {ok, Bookmark, TotalHits, Hits, Counts, Ranges, AwaitTime};
                 false ->
                     Bookmark1 = dreyfus_bookmark:update(Sort, Bookmark, Hits),
                     Hits1 = remove_sortable(Hits),
-                    {ok, Bookmark1, TotalHits, Hits1, Counts, Ranges}
+                    {ok, Bookmark1, TotalHits, Hits1, Counts, Ranges, AwaitTime}
             end;
         {error, Reason} ->
             {error, Reason}
@@ -178,6 +179,17 @@ handle_message({ok, {top_docs, UpdateSeq, TotalHits, Hits}}, Shard, State) ->
         hits = Hits
     },
     handle_message({ok, TopDocs}, Shard, State);
+handle_message({await_time, Time}, Shard, State) ->
+    case fabric_dict:lookup_element(Shard, State#state.counters) of
+        undefined ->
+            %% already heard from someone else in this range
+            {ok, State};
+        nil ->
+            State1 = State#state{
+                await_time = max(Time, State#state.await_time)
+            },
+            {ok, State1}
+    end;
 handle_message(Error, Worker, State0) ->
     State = upgrade_state(State0),
     case
diff --git a/src/dreyfus/src/dreyfus_httpd.erl b/src/dreyfus/src/dreyfus_httpd.erl
index f6607d644..33665db48 100644
--- a/src/dreyfus/src/dreyfus_httpd.erl
+++ b/src/dreyfus/src/dreyfus_httpd.erl
@@ -68,7 +68,7 @@ handle_search_req(
                                 {rows, Hits}
                             ]}
                         );
-                    {ok, Bookmark0, TotalHits, Hits0, Counts0, Ranges0} ->
+                    {ok, Bookmark0, TotalHits, Hits0, Counts0, Ranges0, AwaitTime} ->
                         Hits = hits_to_json(DbName, IncludeDocs, Hits0),
                         Bookmark = dreyfus_bookmark:pack(Bookmark0),
                         Counts =
@@ -85,13 +85,21 @@ handle_search_req(
                                 _ ->
                                     [{ranges, facets_to_json(Ranges0)}]
                             end,
-                        send_json(Req, 200, {
+                        AwaitTimeMs = erlang:convert_time_unit(AwaitTime, native, millisecond),
+                        send_json(
+                            Req,
+                            200,
                             [
-                                {total_rows, TotalHits},
-                                {bookmark, Bookmark},
-                                {rows, Hits}
-                            ] ++ Counts ++ Ranges
-                        });
+                                {"x-cloudant-await-time", integer_to_list(AwaitTimeMs)}
+                            ],
+                            {
+                                [
+                                    {total_rows, TotalHits},
+                                    {bookmark, Bookmark},
+                                    {rows, Hits}
+                                ] ++ Counts ++ Ranges
+                            }
+                        );
                     {error, Reason} ->
                         handle_error(Req, Db, DDoc, RetryCount, RetryPause, Reason)
                 end;
diff --git a/src/dreyfus/src/dreyfus_rpc.erl b/src/dreyfus/src/dreyfus_rpc.erl
index 2ebc5ffe5..4c2e64a8b 100644
--- a/src/dreyfus/src/dreyfus_rpc.erl
+++ b/src/dreyfus/src/dreyfus_rpc.erl
@@ -48,9 +48,12 @@ call(Fun, DbName, DDoc, IndexName, QueryArgs0) ->
         {ok, Index} ->
             case dreyfus_index_manager:get_index(DbName, Index) of
                 {ok, Pid} ->
+                    T0 = erlang:monotonic_time(),
                     case dreyfus_index:await(Pid, MinSeq) of
                         {ok, IndexPid, _Seq} ->
+                            T1 = erlang:monotonic_time(),
                             Result = dreyfus_index:Fun(IndexPid, QueryArgs),
+                            rexi:reply({await_time, T1 - T0}),
                             rexi:reply(Result);
                         % obsolete clauses, remove after upgrade
                         ok ->