You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2018/08/23 10:32:16 UTC

[couchdb] branch user-partitioned-dbs-6 updated (469a02d -> df7efb5)

This is an automated email from the ASF dual-hosted git repository.

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


 discard 469a02d  Add restrictions to partitioned views
     new df7efb5  Add restrictions to partitioned views

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (469a02d)
            \
             N -- N -- N   refs/heads/user-partitioned-dbs-6 (df7efb5)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/chttpd/src/chttpd_view.erl             |  3 ++-
 src/couch_mrview/src/couch_mrview_util.erl | 11 +++++++----
 2 files changed, 9 insertions(+), 5 deletions(-)


[couchdb] 01/01: Add restrictions to partitioned views

Posted by rn...@apache.org.
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 df7efb5919e906fdb975d12d1b2e88410d3f0a38
Author: Robert Newson <rn...@apache.org>
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             |  3 ++-
 src/couch_mrview/src/couch_mrview.erl      | 16 ++++++++++++++++
 src/couch_mrview/src/couch_mrview_util.erl | 12 +++++++++++-
 3 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/src/chttpd/src/chttpd_view.erl b/src/chttpd/src/chttpd_view.erl
index 3c05c64..6b95706 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 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;