summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Newson <rnewson@apache.org>2018-08-22 15:35:51 +0100
committerRobert Newson <rnewson@apache.org>2018-08-30 09:54:15 +0100
commite2ddb722373988995a7f43cf6f4a11b34e94c054 (patch)
treeb78caca75796eee6b56e9f9f27e5356192b02767
parentb0a9b0010d04a8a5b914712324f104dab2624583 (diff)
downloadcouchdb-e2ddb722373988995a7f43cf6f4a11b34e94c054.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.erl3
-rw-r--r--src/couch_mrview/src/couch_mrview.erl16
-rw-r--r--src/couch_mrview/src/couch_mrview_util.erl12
3 files changed, 29 insertions, 2 deletions
diff --git a/src/chttpd/src/chttpd_view.erl b/src/chttpd/src/chttpd_view.erl
index 3c05c64ca..6b9570656 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"},
@@ -42,6 +42,7 @@ multi_query_view(Req, Db, DDoc, ViewName, Queries) ->
design_doc_view(Req, Db, DDoc, ViewName, Keys) ->
Args = couch_mrview_http:parse_params(Req, Keys),
+ couch_mrview_util:validate_args(Args, [view]),
Max = chttpd:chunked_response_buffer_size(),
VAcc = #vacc{db=Db, req=Req, threshold=Max},
Options = [{user_ctx, Req#httpd.user_ctx}],
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;