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 2021/09/23 23:07:03 UTC

[couchdb] branch make-view-row-results-stable created (now e818a3d)

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

vatamane pushed a change to branch make-view-row-results-stable
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


      at e818a3d  Make view merge row aggregation in fabric stable

This branch includes the following new commits:

     new e818a3d  Make view merge row aggregation in fabric stable

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: Make view merge row aggregation in fabric stable

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

vatamane pushed a commit to branch make-view-row-results-stable
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit e818a3d03b78f8a9e64d5111ed469ed45b5d000b
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Thu Sep 23 18:43:14 2021 -0400

    Make view merge row aggregation in fabric stable
    
    We do that by matching the comparator function behavior used during row merging
    [1] in with the comparison function used when sorting the rows on view
    shards [2]. This goes along with the constraint in the lists:merge/3 docs which
    indicates that the input lists should be sorted according to the same
    comparator [3] as the one passed to the lists:merge/3 call.
    
    The stability of returned rows results from the case when both keys match as
    equal. Now `lists:merge/3` will favor the element in the existing rows list
    instead of always replacing [4] the older matching row with the last arriving
    row, since now `less(A, A)` will be `false`, while previously it was `true`.
    
    The fix was found by Adam when discussing issue #3750
    
    https://github.com/apache/couchdb/issues/3750#issuecomment-920947424
    
    Co-author: Adam Kocoloski <ko...@apache.org>
    
    [1] https://github.com/apache/couchdb/blob/3.x/src/fabric/src/fabric_view_map.erl#L244-L248
    [2] https://github.com/apache/couchdb/blob/3.x/src/couch_mrview/src/couch_mrview_util.erl#L1103-L1107
    [3] https://erlang.org/doc/man/lists.html#merge-3
    [4] https://github.com/erlang/otp/blob/master/lib/stdlib/src/lists.erl#L2668-L2675
---
 src/fabric/src/fabric_view.erl     | 1 -
 src/fabric/src/fabric_view_map.erl | 1 -
 2 files changed, 2 deletions(-)

diff --git a/src/fabric/src/fabric_view.erl b/src/fabric/src/fabric_view.erl
index 425f864..bd5e42f 100644
--- a/src/fabric/src/fabric_view.erl
+++ b/src/fabric/src/fabric_view.erl
@@ -298,7 +298,6 @@ transform_row(#view_row{key=Key, id=_Id, value=_Value, doc={error,Reason}}) ->
 transform_row(#view_row{key=Key, id=Id, value=Value, doc=Doc}) ->
     {row, [{id,Id}, {key,Key}, {value,Value}, {doc,Doc}]}.
 
-compare(_, _, A, A) -> true;
 compare(fwd, <<"raw">>, A, B) -> A < B;
 compare(rev, <<"raw">>, A, B) -> B < A;
 compare(fwd, _, A, B) -> couch_ejson_compare:less_json(A, B);
diff --git a/src/fabric/src/fabric_view_map.erl b/src/fabric/src/fabric_view_map.erl
index 8ab8083..adfe7d6 100644
--- a/src/fabric/src/fabric_view_map.erl
+++ b/src/fabric/src/fabric_view_map.erl
@@ -241,7 +241,6 @@ merge_row(Dir, Collation, KeyDict0, Row, Rows0) ->
             {Rows1, KeyDict1}
     end.
 
-compare(_, _, A, A) -> true;
 compare(fwd, <<"raw">>, A, B) -> A < B;
 compare(rev, <<"raw">>, A, B) -> B < A;
 compare(fwd, _, A, B) -> couch_ejson_compare:less_json_ids(A, B);