couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [couchdb] 12/18: add r = 3 restrictions to partition _find and _explain
Date Tue, 18 Sep 2018 14:00:00 GMT
This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch user-partitioned-dbs-7
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 8e997a0e834037e9e417d373b7a0ca1550e9481d
Author: Garren Smith <garren.smith@gmail.com>
AuthorDate: Wed Aug 29 16:47:41 2018 +0200

    add r = 3 restrictions to partition _find and _explain
---
 src/mango/src/mango_error.erl |  7 +++++++
 src/mango/src/mango_httpd.erl |  2 ++
 src/mango/src/mango_opts.erl  | 13 +++++++++++++
 3 files changed, 22 insertions(+)

diff --git a/src/mango/src/mango_error.erl b/src/mango/src/mango_error.erl
index 603fb5f..b5c69b3 100644
--- a/src/mango/src/mango_error.erl
+++ b/src/mango/src/mango_error.erl
@@ -264,6 +264,13 @@ info(mango_opts, {multiple_text_operator, {invalid_selector, BadSel}})
->
             [BadSel])
     };
 
+info(mango_opts, invalid_partition_read) -> 
+    {
+        400,
+        <<"invalid_partition_read_value">>,
+        <<"`r` value can only be r = 1 for partitions">>
+    };
+
 info(mango_selector, {invalid_selector, missing_field_name}) ->
     {
         400,
diff --git a/src/mango/src/mango_httpd.erl b/src/mango/src/mango_httpd.erl
index ca867fa..77a73c1 100644
--- a/src/mango/src/mango_httpd.erl
+++ b/src/mango/src/mango_httpd.erl
@@ -208,6 +208,7 @@ handle_partition_explain_req(#httpd{method='POST'}=Req, Db, Partition)
->
     chttpd:validate_ctype(Req, "application/json"),
     {ok, Body} = add_partition_to_query(Req, Partition),
     {ok, Opts0} = mango_opts:validate_find(Body),
+    ok = mango_opts:validate_partition(Body),
     {value, {selector, Sel}, Opts} = lists:keytake(selector, 1, Opts0),
     Resp = mango_crud:explain(Db, Sel, Opts),
     chttpd:send_json(Req, Resp);
@@ -234,6 +235,7 @@ handle_partition_find_req(#httpd{method='POST'}=Req, Db, Partition) ->
     chttpd:validate_ctype(Req, "application/json"),
     {ok, Body} = add_partition_to_query(Req, Partition),
     {ok, Opts0} = mango_opts:validate_find(Body),
+    ok = mango_opts:validate_partition(Body),
     {value, {selector, Sel}, Opts} = lists:keytake(selector, 1, Opts0),
     {ok, Resp0} = start_find_resp(Req),
     {ok, AccOut} = run_find(Resp0, Db, Sel, Opts),
diff --git a/src/mango/src/mango_opts.erl b/src/mango/src/mango_opts.erl
index d846287..365e248 100644
--- a/src/mango/src/mango_opts.erl
+++ b/src/mango/src/mango_opts.erl
@@ -34,6 +34,7 @@
     validate_sort/1,
     validate_fields/1,
     validate_bulk_delete/1,
+    validate_partition/1,
 
     default_limit/0
 ]).
@@ -357,3 +358,15 @@ validate_opt(Name, [{validator, Fun} | Rest], Value) ->
 
 default_limit() ->
     config:get_integer("mango", "default_limit", 25).
+
+
+validate_partition({Props}) ->
+    case lists:keyfind(<<"r">>, 1, Props) of
+        false ->
+            ok;
+        {<<"r">>, 1} ->
+            ok;
+        {<<"r">>, _Value} ->
+            ?MANGO_ERROR(invalid_partition_read)
+
+    end.


Mime
View raw message