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/07/17 12:39:27 UTC

[couchdb] 01/03: move partition flag into view options

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

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

commit ba58da3634bf64875343a0689490c942cf361af2
Author: Robert Newson <rn...@apache.org>
AuthorDate: Mon Jul 16 15:19:12 2018 +0100

    move partition flag into view options
---
 .../test/fixtures/3b835456c235b1827e012e25666152f3.view  | Bin 4192 -> 0 bytes
 src/couch_mrview/src/couch_mrview_index.erl              |   4 +++-
 src/couch_mrview/src/couch_mrview_util.erl               |  14 +++++++-------
 src/fabric/src/fabric.erl                                |   4 ++--
 4 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/couch/test/fixtures/3b835456c235b1827e012e25666152f3.view b/src/couch/test/fixtures/3b835456c235b1827e012e25666152f3.view
deleted file mode 100644
index 9c67648..0000000
Binary files a/src/couch/test/fixtures/3b835456c235b1827e012e25666152f3.view and /dev/null differ
diff --git a/src/couch_mrview/src/couch_mrview_index.erl b/src/couch_mrview/src/couch_mrview_index.erl
index 5d285d6..2d462d9 100644
--- a/src/couch_mrview/src/couch_mrview_index.erl
+++ b/src/couch_mrview/src/couch_mrview_index.erl
@@ -38,10 +38,12 @@ get(update_options, #mrst{design_opts = Opts}) ->
     LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
     SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
     KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
+    Partitioned = couch_util:get_value(<<"partitioned">>, Opts, false),
     if IncDesign -> [include_design]; true -> [] end
         ++ if LocalSeq -> [local_seq]; true -> [] end
         ++ if KeySeqIndexed -> [keyseq_indexed]; true -> [] end
-        ++ if SeqIndexed -> [seq_indexed]; true -> [] end;
+        ++ if SeqIndexed -> [seq_indexed]; true -> [] end
+        ++ if Partitioned -> [partitioned]; true -> [] end;
 get(fd, #mrst{fd = Fd}) ->
     Fd;
 get(language, #mrst{language = Language}) ->
diff --git a/src/couch_mrview/src/couch_mrview_util.erl b/src/couch_mrview/src/couch_mrview_util.erl
index 5bb25b4..e50ab77 100644
--- a/src/couch_mrview/src/couch_mrview_util.erl
+++ b/src/couch_mrview/src/couch_mrview_util.erl
@@ -135,6 +135,7 @@ ddoc_to_mrst(DbName, #doc{id=Id, body={Fields}}) ->
     {DesignOpts} = proplists:get_value(<<"options">>, Fields, {[]}),
     SeqIndexed = proplists:get_value(<<"seq_indexed">>, DesignOpts, false),
     KeySeqIndexed = proplists:get_value(<<"keyseq_indexed">>, DesignOpts, false),
+    Partitioned = proplists:get_value(<<"partitioned">>, DesignOpts, false),
 
     {RawViews} = couch_util:get_value(<<"views">>, Fields, {[]}),
     BySrc = lists:foldl(MakeDict, dict:new(), RawViews),
@@ -155,7 +156,8 @@ ddoc_to_mrst(DbName, #doc{id=Id, body={Fields}}) ->
         language=Language,
         design_opts=DesignOpts,
         seq_indexed=SeqIndexed,
-        keyseq_indexed=KeySeqIndexed
+        keyseq_indexed=KeySeqIndexed,
+        partitioned=Partitioned
     },
     SigInfo = {Views, Language, DesignOpts, couch_index_util:sort_lib(Lib)},
     {ok, IdxState#mrst{sig=crypto:hash(md5, term_to_binary(SigInfo))}}.
@@ -281,7 +283,6 @@ init_state(Db, Fd, State, Header) ->
 
     OpenViewFun = fun(St, View) -> open_view(Db, Fd, Lang, St, View) end,
     Views2 = lists:zipwith(OpenViewFun, ViewStates, Views),
-    Partitioned = couch_db_engine:get_partitioned(Db),
 
     State#mrst{
         fd=Fd,
@@ -290,8 +291,7 @@ init_state(Db, Fd, State, Header) ->
         purge_seq=PurgeSeq,
         id_btree=IdBtree,
         log_btree=LogBtree,
-        views=Views2,
-        partitioned=Partitioned
+        views=Views2
     }.
 
 open_view(_Db, Fd, Lang, ViewState, View) ->
@@ -554,14 +554,14 @@ validate_args(Args) ->
         _ -> mrverror(<<"Invalid value for `sorted`.">>)
     end,
 
-    case {Args#mrargs.partitioned, Args#mrargs.partition} of
+    case {Args#mrargs.partitioned == true, Args#mrargs.partition} of
         {true, undefined} ->
             mrverror(<<"`partition` parameter is mandatory for queries to this database.">>);
         {true, _Partition} ->
             ok;
-        {undefined, undefined} ->
+        {false, undefined} ->
             ok;
-        {undefined, _Partition} ->
+        {false, _Partition} ->
             mrverror(<<"`partition` parameter is not supported in this database.">>)
     end,
     Args.
diff --git a/src/fabric/src/fabric.erl b/src/fabric/src/fabric.erl
index 308de64..c7a47b0 100644
--- a/src/fabric/src/fabric.erl
+++ b/src/fabric/src/fabric.erl
@@ -354,10 +354,10 @@ query_view(DbName, Options, DDoc, ViewName, Callback, Acc0, QueryArgs0) ->
     false ->
         ok
     end,
-    {ok, #mrst{views=Views, language=Lang}} =
+    {ok, #mrst{views=Views, language=Lang, design_opts=DesignOpts}} =
         couch_mrview_util:ddoc_to_mrst(Db, DDoc),
 
-    Partitioned = mem3:is_partitioned(Db),
+    Partitioned = couch_util:get_value(<<"partitioned">>, DesignOpts, false),
 
     QueryArgs1 = couch_mrview_util:set_view_type(QueryArgs0, View, Views),
     QueryArgs2 = couch_mrview_util:set_view_options(QueryArgs1, partitioned, Partitioned),