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 2021/12/20 17:08:14 UTC

[couchdb] branch enforce_rowlimit_mango created (now d81d598)

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

rnewson pushed a change to branch enforce_rowlimit_mango
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


      at d81d598  Apply partition_query_limit and query_limit to _find

This branch includes the following new commits:

     new 5705057  rename ignore_partition_query_limit to is_mango_query for clarity
     new d81d598  Apply partition_query_limit and query_limit to _find

The 2 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/02: rename ignore_partition_query_limit to is_mango_query for clarity

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

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

commit 57050578d3ff2bc8b08e1f4451183c46f182605c
Author: Robert Newson <rn...@apache.org>
AuthorDate: Mon Dec 20 16:05:15 2021 +0000

    rename ignore_partition_query_limit to is_mango_query for clarity
---
 src/couch_mrview/src/couch_mrview_util.erl | 38 ++++++++++++++++--------------
 src/mango/src/mango_cursor_view.erl        |  2 +-
 2 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/src/couch_mrview/src/couch_mrview_util.erl b/src/couch_mrview/src/couch_mrview_util.erl
index b7220f7..41594ff 100644
--- a/src/couch_mrview/src/couch_mrview_util.erl
+++ b/src/couch_mrview/src/couch_mrview_util.erl
@@ -439,28 +439,30 @@ validate_args(#mrst{} = State, Args0) ->
             mrverror(Msg2)
     end.
 
-apply_limit(ViewPartitioned, Args) ->
-    Options = Args#mrargs.extra,
-    IgnorePQLimit = lists:keyfind(ignore_partition_query_limit, 1, Options),
-    LimitType =
-        case {ViewPartitioned, IgnorePQLimit} of
-            {true, false} -> "partition_query_limit";
-            {true, _} -> "query_limit";
-            {false, _} -> "query_limit"
-        end,
+apply_limit(ViewPartitioned, #mrargs{} = Args) ->
+    LimitType = case ViewPartitioned of
+        true -> "partition_query_limit";
+        false -> "query_limit"
+    end,
 
-    MaxLimit = config:get_integer(
-        "query_server_config",
-        LimitType,
-        ?MAX_VIEW_LIMIT
-    ),
+    IsMangoQuery = lists:keyfind(is_mango_query, 1, Args#mrargs.extra),
+    MaxLimit = case IsMangoQuery of
+        {is_mango_query, true} ->
+            ?MAX_VIEW_LIMIT;
+        false ->
+            config:get_integer(
+                "query_server_config",
+                LimitType,
+                ?MAX_VIEW_LIMIT)
+    end,
 
     % Set the highest limit possible if a user has not
-    % specified a limit
+    % specified a limit or if this is a mango query
     Args1 =
-        case Args#mrargs.limit == ?MAX_VIEW_LIMIT of
-            true -> Args#mrargs{limit = MaxLimit};
-            false -> Args
+        case {Args#mrargs.limit == ?MAX_VIEW_LIMIT, IsMangoQuery} of
+            {_, {is_mango_query, true}} -> Args#mrargs{limit = ?MAX_VIEW_LIMIT};
+            {true, false} -> Args#mrargs{limit = MaxLimit};
+            {false, false} -> Args
         end,
 
     if
diff --git a/src/mango/src/mango_cursor_view.erl b/src/mango/src/mango_cursor_view.erl
index 5656ffc..eb2271b 100644
--- a/src/mango/src/mango_cursor_view.erl
+++ b/src/mango/src/mango_cursor_view.erl
@@ -120,7 +120,7 @@ base_args(#cursor{index = Idx, selector = Selector} = Cursor) ->
         extra = [
             {callback, {?MODULE, view_cb}},
             {selector, Selector},
-            {ignore_partition_query_limit, true}
+            {is_mango_query, true}
         ]
     }.
 

[couchdb] 02/02: Apply partition_query_limit and query_limit to _find

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

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

commit d81d59822ffc739a5f9d48ec6e4e1a643cbac785
Author: Robert Newson <rn...@apache.org>
AuthorDate: Mon Dec 20 17:07:37 2021 +0000

    Apply partition_query_limit and query_limit to _find
---
 src/mango/src/mango_cursor_special.erl |  3 ++-
 src/mango/src/mango_cursor_view.erl    |  3 ++-
 src/mango/src/mango_opts.erl           | 10 +++++++++-
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/mango/src/mango_cursor_special.erl b/src/mango/src/mango_cursor_special.erl
index f20edeb..6453e95 100644
--- a/src/mango/src/mango_cursor_special.erl
+++ b/src/mango/src/mango_cursor_special.erl
@@ -36,7 +36,8 @@ create(Db, Indexes, Selector, Opts) ->
     Composited = mango_cursor_view:composite_indexes(Indexes, FieldRanges),
     {Index, IndexRanges} = mango_cursor_view:choose_best_index(Db, Composited),
 
-    Limit = couch_util:get_value(limit, Opts, mango_opts:default_limit()),
+    MRLimit = mango_opts:mr_limit(couch_db:is_partitioned(Db)),
+    Limit = erlang:min(MRLimit, couch_util:get_value(limit, Opts, mango_opts:default_limit())),
     Skip = couch_util:get_value(skip, Opts, 0),
     Fields = couch_util:get_value(fields, Opts, all_fields),
     Bookmark = couch_util:get_value(bookmark, Opts),
diff --git a/src/mango/src/mango_cursor_view.erl b/src/mango/src/mango_cursor_view.erl
index eb2271b..0142d36 100644
--- a/src/mango/src/mango_cursor_view.erl
+++ b/src/mango/src/mango_cursor_view.erl
@@ -40,7 +40,8 @@ create(Db, Indexes, Selector, Opts) ->
     Composited = composite_indexes(Indexes, FieldRanges),
     {Index, IndexRanges} = choose_best_index(Db, Composited),
 
-    Limit = couch_util:get_value(limit, Opts, mango_opts:default_limit()),
+    MRLimit = mango_opts:mr_limit(couch_db:is_partitioned(Db)),
+    Limit = erlang:min(MRLimit, couch_util:get_value(limit, Opts, mango_opts:default_limit())),
     Skip = couch_util:get_value(skip, Opts, 0),
     Fields = couch_util:get_value(fields, Opts, all_fields),
     Bookmark = couch_util:get_value(bookmark, Opts),
diff --git a/src/mango/src/mango_opts.erl b/src/mango/src/mango_opts.erl
index 04fe5bb..2bf76fa 100644
--- a/src/mango/src/mango_opts.erl
+++ b/src/mango/src/mango_opts.erl
@@ -36,10 +36,12 @@
     validate_bulk_delete/1,
     validate_partitioned/1,
 
-    default_limit/0
+    default_limit/0,
+    mr_limit/1
 ]).
 
 -include("mango.hrl").
+-include_lib("couch_mrview/include/couch_mrview.hrl").
 
 validate_idx_create({Props}) ->
     Opts = [
@@ -356,3 +358,9 @@ validate_opt(Name, [{validator, Fun} | Rest], Value) ->
 
 default_limit() ->
     config:get_integer("mango", "default_limit", 25).
+
+
+mr_limit(true) ->
+    config:get_integer("query_server_config", "partition_query_limit", ?MAX_VIEW_LIMIT);
+mr_limit(false) ->
+    config:get_integer("query_server_config", "query_limit", ?MAX_VIEW_LIMIT).