summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Newson <rnewson@apache.org>2018-08-22 15:35:51 +0100
committerRobert Newson <rnewson@apache.org>2018-09-03 17:43:04 +0100
commit7395c704d92dfc0f429b0a2c2de95cf1bbba0617 (patch)
treee5a6d3e45da60c3bc879d16e287ca3bc70dd784d
parent6e704f58f29456ba8a00d4d82282c8b0bf5e6f91 (diff)
downloadcouchdb-7395c704d92dfc0f429b0a2c2de95cf1bbba0617.tar.gz
Add restrictions to partitioned views
* Block design documents with partitioned option in non-partitioned db * Prohibit javascript reduces in partitioned:true ddocs * Prohibit include_docs=true for _view in partitioned db
-rw-r--r--src/chttpd/src/chttpd_view.erl2
-rw-r--r--src/couch_mrview/src/couch_mrview.erl16
-rw-r--r--src/couch_mrview/src/couch_mrview_util.erl12
-rw-r--r--src/fabric/src/fabric.erl2
4 files changed, 29 insertions, 3 deletions
diff --git a/src/chttpd/src/chttpd_view.erl b/src/chttpd/src/chttpd_view.erl
index 3c05c64ca..e75344f63 100644
--- a/src/chttpd/src/chttpd_view.erl
+++ b/src/chttpd/src/chttpd_view.erl
@@ -24,7 +24,7 @@ multi_query_view(Req, Db, DDoc, ViewName, Queries) ->
QueryArg = couch_mrview_http:parse_params(Query, undefined,
Args1, [decoded]),
QueryArg1 = couch_mrview_util:set_view_type(QueryArg, ViewName, Views),
- couch_mrview_util:validate_args(QueryArg1)
+ couch_mrview_util:validate_args(QueryArg1, [view])
end, Queries),
Options = [{user_ctx, Req#httpd.user_ctx}],
VAcc0 = #vacc{db=Db, req=Req, prepend="\r\n"},
diff --git a/src/couch_mrview/src/couch_mrview.erl b/src/couch_mrview/src/couch_mrview.erl
index f5963e70f..7862afb1e 100644
--- a/src/couch_mrview/src/couch_mrview.erl
+++ b/src/couch_mrview/src/couch_mrview.erl
@@ -176,6 +176,16 @@ join([H|T], Sep, Acc) ->
validate(DbName, DDoc) ->
ok = validate_ddoc_fields(DDoc#doc.body),
+ DbPartitioned = mem3:is_partitioned(DbName),
+ DDocPartitioned = get_partitioned_opt(DDoc#doc.body, DbPartitioned),
+ if
+ not DbPartitioned andalso DDocPartitioned ->
+ throw({invalid_design_doc,
+ <<"partitioned option cannot be true in a "
+ "non-partitioned database.">>});
+ true ->
+ ok
+ end,
GetName = fun
(#mrview{map_names = [Name | _]}) -> Name;
(#mrview{reduce_funs = [{Name, _} | _]}) -> Name;
@@ -195,6 +205,9 @@ validate(DbName, DDoc) ->
({_RedName, <<"_", _/binary>> = Bad}) ->
Msg = ["`", Bad, "` is not a supported reduce function."],
throw({invalid_design_doc, Msg});
+ ({_RedName, _RedSrc}) when DDocPartitioned ->
+ Msg = <<"Javascript reduces not supported in partitioned view.">>,
+ throw({invalid_design_doc, Msg});
({RedName, RedSrc}) ->
couch_query_servers:try_compile(Proc, reduce, RedName, RedSrc)
end, Reds)
@@ -215,6 +228,9 @@ validate(DbName, DDoc) ->
ok
end.
+get_partitioned_opt({Props}, Default) ->
+ {Options} = couch_util:get_value(<<"options">>, Props, {[]}),
+ couch_util:get_value(<<"partitioned">>, Options, Default).
query_all_docs(Db, Args) ->
query_all_docs(Db, Args, fun default_cb/2, []).
diff --git a/src/couch_mrview/src/couch_mrview_util.erl b/src/couch_mrview/src/couch_mrview_util.erl
index 02e695dd0..794b69482 100644
--- a/src/couch_mrview/src/couch_mrview_util.erl
+++ b/src/couch_mrview/src/couch_mrview_util.erl
@@ -24,7 +24,7 @@
-export([temp_view_to_ddoc/1]).
-export([calculate_external_size/1]).
-export([calculate_active_size/1]).
--export([validate_args/1]).
+-export([validate_args/1, validate_args/2]).
-export([maybe_load_doc/3, maybe_load_doc/4]).
-export([maybe_update_index_file/1]).
-export([extract_view/4, extract_view_reduce/1]).
@@ -465,6 +465,9 @@ fold_reduce({NthRed, Lang, View}, Fun, Acc, Options) ->
validate_args(Args) ->
+ validate_args(Args, []).
+
+validate_args(Args, ValidateOptions) ->
GroupLevel = determine_group_level(Args),
Reduce = Args#mrargs.reduce,
case Reduce == undefined orelse is_boolean(Reduce) of
@@ -607,6 +610,13 @@ validate_args(Args) ->
mrverror(<<"`partition` parameter is not supported in this view.">>)
end,
+ case {Partitioned, Args#mrargs.include_docs, ValidateOptions} of
+ {true, true, [view]} ->
+ mrverror(<<"`include_docs=true` is not supported in this view.">>);
+ {_, _, _} ->
+ ok
+ end,
+
Args1 = case {Style, Partitioned, Partition} of
{all_docs, true, undefined} ->
Args;
diff --git a/src/fabric/src/fabric.erl b/src/fabric/src/fabric.erl
index f5c793736..fcdbb2a72 100644
--- a/src/fabric/src/fabric.erl
+++ b/src/fabric/src/fabric.erl
@@ -356,7 +356,7 @@ query_view(DbName, Options, DDoc, ViewName, Callback, Acc0, QueryArgs0) ->
{ok, #mrst{views=Views, language=Lang}} =
couch_mrview_util:ddoc_to_mrst(Db, DDoc),
QueryArgs1 = couch_mrview_util:set_view_type(QueryArgs0, View, Views),
- QueryArgs2 = couch_mrview_util:validate_args(QueryArgs1),
+ QueryArgs2 = couch_mrview_util:validate_args(QueryArgs1, [view]),
VInfo = couch_mrview_util:extract_view(Lang, QueryArgs2, View, Views),
case is_reduce_view(QueryArgs2) of
true ->