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/22 16:45:42 UTC
[couchdb] 01/01: Add restrictions to partitioned views
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 1a76362f194a5818f7a6ed6dc0c85dd767df435e
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
---
src/couch_mrview/src/couch_mrview.erl | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
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, []).