This is an automated email from the ASF dual-hosted git repository.
rnewson pushed a commit to branch user-partitioned-dbs-6
in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/user-partitioned-dbs-6 by this
push:
new 669cb60 add r = 3 restrictions to partition _find and _explain
669cb60 is described below
commit 669cb60f5bcd32f32b2f2fb154f39446819a8761
Author: Garren Smith <[email protected]>
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 9a5c266..d9589b3 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 87d876a..f1b7b60 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
]).
@@ -351,3 +352,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.