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

commit 7395c704d92dfc0f429b0a2c2de95cf1bbba0617
Author: Robert Newson <[email protected]>
AuthorDate: Wed Aug 22 15:35:51 2018 +0100

    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
---
 src/chttpd/src/chttpd_view.erl             |  2 +-
 src/couch_mrview/src/couch_mrview.erl      | 16 ++++++++++++++++
 src/couch_mrview/src/couch_mrview_util.erl | 12 +++++++++++-
 src/fabric/src/fabric.erl                  |  2 +-
 4 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/src/chttpd/src/chttpd_view.erl b/src/chttpd/src/chttpd_view.erl
index 3c05c64..e75344f 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 f5963e7..7862afb 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 02e695d..794b694 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 f5c7937..fcdbb2a 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 ->

Reply via email to