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/08/24 04:54:05 UTC

(couchdb) branch fix-changes-descending-over-limit-case updated (9694faf74 -> 2011f7747)

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

vatamane pushed a change to branch fix-changes-descending-over-limit-case
in repository https://gitbox.apache.org/repos/asf/couchdb.git


 discard 9694faf74 Fix reverse continuous changes feeds with limit greater than total
     new 2011f7747 Fix reverse continuous changes feeds with limit greater than total

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   (9694faf74)
            \
             N -- N -- N   refs/heads/fix-changes-descending-over-limit-case (2011f7747)

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/fabric/src/fabric_view_changes.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


(couchdb) 01/01: Fix reverse continuous changes feeds with limit greater than total

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

vatamane pushed a commit to branch fix-changes-descending-over-limit-case
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 2011f77470f727357387c7e71518727a9d95ed82
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Sat Aug 24 00:50:39 2024 -0400

    Fix reverse continuous changes feeds with limit greater than total
    
    Previously, `_changes?feed=continuous&descending=true&limit=N` with `N` greater
    than total rows would block and wait on database changes. On each change the
    first few sequence rows (sequences `1-...`, `2-...`) were repeatedly emitted.
    The new behavior is to return after all the rows are emitted.
    
    Fix: #5203
---
 src/chttpd/test/eunit/chttpd_changes_test.erl | 20 ++++++++++++++++++++
 src/docs/src/whatsnew/3.4.rst                 |  8 ++++++++
 src/fabric/src/fabric_view_changes.erl        | 12 +++++++-----
 3 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/src/chttpd/test/eunit/chttpd_changes_test.erl b/src/chttpd/test/eunit/chttpd_changes_test.erl
index 8e6a6a0db..b93667752 100644
--- a/src/chttpd/test/eunit/chttpd_changes_test.erl
+++ b/src/chttpd/test/eunit/chttpd_changes_test.erl
@@ -73,6 +73,10 @@ changes_test_() ->
             ?TDEF(t_style_all_docs),
             ?TDEF(t_reverse),
             ?TDEF(t_continuous_reverse),
+            ?TDEF(t_continuous_reverse_limit_0),
+            ?TDEF(t_continuous_reverse_limit_under_total),
+            ?TDEF(t_continuous_reverse_limit_exact_total),
+            ?TDEF(t_continuous_reverse_limit_over_total),
             ?TDEF(t_reverse_limit_zero),
             ?TDEF(t_reverse_limit_one),
             ?TDEF(t_seq_interval),
@@ -364,6 +368,22 @@ t_continuous_reverse({_, DbUrl}) ->
         Rows
     ).
 
+t_continuous_reverse_limit_0({_, DbUrl}) ->
+    Params = "?feed=continuous&descending=true&limit=0",
+    ?assertEqual({8, 3, []}, changes(DbUrl, Params)).
+
+t_continuous_reverse_limit_under_total({_, DbUrl}) ->
+    Params = "?feed=continuous&descending=true&limit=1",
+    ?assertMatch({8, 2, [{8, _, _}]}, changes(DbUrl, Params)).
+
+t_continuous_reverse_limit_exact_total({_, DbUrl}) ->
+    Params = "?feed=continuous&descending=true&limit=3",
+    ?assertMatch({6, 0, [{8, _, _}, {7, _, _}, {6, _, _}]}, changes(DbUrl, Params)).
+
+t_continuous_reverse_limit_over_total({_, DbUrl}) ->
+    Params = "?feed=continuous&descending=true&limit=999",
+    ?assertMatch({6, 0, [{8, _, _}, {7, _, _}, {6, _, _}]}, changes(DbUrl, Params)).
+
 t_reverse_q8({_, DbUrl}) ->
     Params = "?descending=true",
     {Seq, Pending, Rows} = changes(DbUrl, Params),
diff --git a/src/docs/src/whatsnew/3.4.rst b/src/docs/src/whatsnew/3.4.rst
index 4693d4680..58293ae6a 100644
--- a/src/docs/src/whatsnew/3.4.rst
+++ b/src/docs/src/whatsnew/3.4.rst
@@ -39,6 +39,14 @@ Breaking Changes
   We recommend adding ``nbf`` as a required claim if you know your tokens will
   include it.
 
+* :ghissue:`5203`: Continuous change feeds with ``descending=true&limit=N``
+
+  Previously, ``_changes?feed=continuous&descending=true&limit=N`` with ``N``
+  greater than total rows would block and wait on database changes. On each
+  change the first few sequence rows (sequences ``1-...``, ``2-...``) were
+  repeatedly emitted. The new behavior is to return after all the rows are
+  emitted.
+
 Highlights
 ----------
 
diff --git a/src/fabric/src/fabric_view_changes.erl b/src/fabric/src/fabric_view_changes.erl
index fac76f763..33b33e487 100644
--- a/src/fabric/src/fabric_view_changes.erl
+++ b/src/fabric/src/fabric_view_changes.erl
@@ -87,7 +87,7 @@ go(DbName, "normal", Options, Callback, Acc0) ->
     end.
 
 keep_sending_changes(DbName, Args, Callback, Seqs, AccIn, Timeout, UpListen, T0) ->
-    #changes_args{limit = Limit, feed = Feed, heartbeat = Heartbeat} = Args,
+    #changes_args{limit = Limit, feed = Feed, heartbeat = Heartbeat, dir = Dir} = Args,
     {ok, Collector} = send_changes(DbName, Args, Callback, Seqs, AccIn, Timeout),
     #collector{
         limit = Limit2,
@@ -98,13 +98,15 @@ keep_sending_changes(DbName, Args, Callback, Seqs, AccIn, Timeout, UpListen, T0)
     LastSeq = pack_seqs(NewSeqs),
     MaintenanceMode = config:get("couchdb", "maintenance_mode"),
     NewEpoch = get_changes_epoch() > erlang:get(changes_epoch),
+    PendingCount = pending_count(Offset),
     if
+        Dir == rev, PendingCount =< 0;
         Limit2 =< 0, (Feed == "continuous" orelse Feed == "eventsource");
         Limit > Limit2, Feed == "longpoll";
         MaintenanceMode == "true";
         MaintenanceMode == "nolb";
         NewEpoch ->
-            Callback({stop, LastSeq, pending_count(Offset)}, AccOut0);
+            Callback({stop, LastSeq, PendingCount}, AccOut0);
         true ->
             {ok, AccOut} = Callback(waiting_for_updates, AccOut0),
             WaitForUpdate = wait_db_updated(UpListen),
@@ -118,11 +120,11 @@ keep_sending_changes(DbName, Args, Callback, Seqs, AccIn, Timeout, UpListen, T0)
                 end,
             case {Heartbeat, AccumulatedTime > Max, WaitForUpdate} of
                 {_, _, changes_feed_died} ->
-                    Callback({stop, LastSeq, pending_count(Offset)}, AccOut);
+                    Callback({stop, LastSeq, PendingCount}, AccOut);
                 {undefined, _, timeout} ->
-                    Callback({stop, LastSeq, pending_count(Offset)}, AccOut);
+                    Callback({stop, LastSeq, PendingCount}, AccOut);
                 {_, true, timeout} ->
-                    Callback({stop, LastSeq, pending_count(Offset)}, AccOut);
+                    Callback({stop, LastSeq, PendingCount}, AccOut);
                 _ ->
                     {ok, AccTimeout} = Callback(timeout, AccOut),
                     Args1 = Args#changes_args{limit = Limit2},