You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/02/06 17:54:20 UTC

[01/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Updated Branches:
  refs/heads/import-rcouch [created] 725894562


Do not log errors on creating new view index.

While view index file may be really missed, it's ok for new views
and this error will be self-healed on next couch_file:open call
so there is no reason to worry user about.

COUCHDB-1666

Patch by Alexander Shorin.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/cab082b5
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/cab082b5
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/cab082b5

Branch: refs/heads/import-rcouch
Commit: cab082b58586a814190bcd4655391ba405a89f76
Parents: fda4ebc
Author: Jan Lehnardt <ja...@apache.org>
Authored: Mon Feb 4 11:39:26 2013 +0100
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Mon Feb 4 11:39:26 2013 +0100

----------------------------------------------------------------------
 src/couch_mrview_util.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/cab082b5/src/couch_mrview_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_util.erl b/src/couch_mrview_util.erl
index ba4de2d..8e6e4dc 100644
--- a/src/couch_mrview_util.erl
+++ b/src/couch_mrview_util.erl
@@ -513,7 +513,7 @@ compaction_file(DbName, Sig) ->
 
 
 open_file(FName) ->
-    case couch_file:open(FName) of
+    case couch_file:open(FName, [nologifmissing]) of
         {ok, Fd} -> {ok, Fd};
         {error, enoent} -> couch_file:open(FName, [create]);
         Error -> Error


[15/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
remove Makefile.am from apps/ and fix couchspawnkillable


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/bfd7b436
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/bfd7b436
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/bfd7b436

Branch: refs/heads/import-rcouch
Commit: bfd7b436f37738953b15e5723ac12ee824d43e9f
Parents: cb13142
Author: benoitc <be...@apache.org>
Authored: Tue Jan 7 19:15:43 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Thu Feb 6 10:51:40 2014 -0600

----------------------------------------------------------------------
 Makefile.am | 73 --------------------------------------------------------
 1 file changed, 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/bfd7b436/Makefile.am
----------------------------------------------------------------------
diff --git a/Makefile.am b/Makefile.am
deleted file mode 100644
index 2b9ef86..0000000
--- a/Makefile.am
+++ /dev/null
@@ -1,73 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-##   http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-couch_mrviewlibdir = $(localerlanglibdir)/couch_mrview-0.1
-couch_mrviewincludedir = $(couch_mrviewlibdir)/include
-couch_mrviewebindir = $(couch_mrviewlibdir)/ebin
-
-couch_mrviewinclude_DATA = $(include_files)
-couch_mrviewebin_DATA = $(compiled_files)
-
-include_files = \
-    include/couch_mrview.hrl
-
-source_files = \
-    src/couch_mrview.app.src \
-    src/couch_mrview.erl \
-    src/couch_mrview_cleanup.erl \
-    src/couch_mrview_compactor.erl \
-    src/couch_mrview_http.erl \
-    src/couch_mrview_index.erl \
-    src/couch_mrview_show.erl \
-    src/couch_mrview_test_util.erl \
-    src/couch_mrview_updater.erl \
-    src/couch_mrview_util.erl
-
-test_files = \
-    test/01-load.t \
-    test/02-map-views.t \
-    test/03-red-views.t \
-    test/04-index-info.t \
-    test/05-collation.t \
-    test/06-all-docs.t \
-	test/07-compact-swap.t
-
-compiled_files = \
-    ebin/couch_mrview.app \
-    ebin/couch_mrview.beam \
-    ebin/couch_mrview_cleanup.beam \
-    ebin/couch_mrview_compactor.beam \
-    ebin/couch_mrview_http.beam \
-    ebin/couch_mrview_index.beam \
-    ebin/couch_mrview_show.beam \
-    ebin/couch_mrview_test_util.beam \
-    ebin/couch_mrview_updater.beam \
-    ebin/couch_mrview_util.beam
-
-EXTRA_DIST = $(include_files) $(source_files) $(test_files)
-CLEANFILES = $(compiled_files)
-
-check:
-if TESTS
-	$(abs_top_builddir)/test/etap/run $(abs_top_srcdir)/src/couch_mrview/test
-endif
-
-ebin/%.app: src/%.app.src
-	@mkdir -p ebin/
-	sed -e "s|%version%|@version@|g" \
-	< $< > $@
-
-ebin/%.beam: src/%.erl $(include_files)
-	@mkdir -p ebin/
-	$(ERLC) -Wall -I$(top_srcdir)/src -I$(top_srcdir)/src/couchdb \
-        -o ebin/ $(ERLC_FLAGS) ${TEST} $<;
-


[05/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
COUCHDB-1334 - revert "More efficient communication with the view server"

This reverts commit a851c6e
- COUCHDB-1334 breaks with Windows + couchjs in unexplained ways
- reducing to 1 concurrent query server is not sufficient
- Testing with open_port options overlapped_io was not in itself sufficient
- http://erlang.org/doc/man/erlang.html find overlapped_io
- Refer history in COUCHDB-1346


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/ad50fe95
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/ad50fe95
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/ad50fe95

Branch: refs/heads/import-rcouch
Commit: ad50fe95150e24a3205195755351ceaa0918e4ea
Parents: 3651497
Author: Dave Cottlehuber <dc...@apache.org>
Authored: Wed Dec 12 21:37:18 2012 +0100
Committer: Dave Cottlehuber <dc...@apache.org>
Committed: Tue Jul 23 13:14:33 2013 +0200

----------------------------------------------------------------------
 src/couch_mrview_updater.erl | 46 +++++++++++++++------------------------
 1 file changed, 18 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/ad50fe95/src/couch_mrview_updater.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_updater.erl b/src/couch_mrview_updater.erl
index 3014664..9604ea9 100644
--- a/src/couch_mrview_updater.erl
+++ b/src/couch_mrview_updater.erl
@@ -130,42 +130,32 @@ map_docs(Parent, State0) ->
             couch_query_servers:stop_doc_map(State0#mrst.qserver),
             couch_work_queue:close(State0#mrst.write_queue);
         {ok, Dequeued} ->
+            % Run all the non deleted docs through the view engine and
+            % then pass the results on to the writer process.
             State1 = case State0#mrst.qserver of
                 nil -> start_query_server(State0);
                 _ -> State0
             end,
-            {ok, MapResults} = compute_map_results(State1, Dequeued),
-            couch_work_queue:queue(State1#mrst.write_queue, MapResults),
+            QServer = State1#mrst.qserver,
+            DocFun = fun
+                ({nil, Seq, _}, {SeqAcc, Results}) ->
+                    {erlang:max(Seq, SeqAcc), Results};
+                ({Id, Seq, deleted}, {SeqAcc, Results}) ->
+                    {erlang:max(Seq, SeqAcc), [{Id, []} | Results]};
+                ({Id, Seq, Doc}, {SeqAcc, Results}) ->
+                    {ok, Res} = couch_query_servers:map_doc_raw(QServer, Doc),
+                    {erlang:max(Seq, SeqAcc), [{Id, Res} | Results]}
+            end,
+            FoldFun = fun(Docs, Acc) ->
+                update_task(length(Docs)),
+                lists:foldl(DocFun, Acc, Docs)
+            end,
+            Results = lists:foldl(FoldFun, {0, []}, Dequeued),
+            couch_work_queue:queue(State1#mrst.write_queue, Results),
             map_docs(Parent, State1)
     end.
 
 
-compute_map_results(#mrst{qserver = Qs}, Dequeued) ->
-    % Run all the non deleted docs through the view engine and
-    % then pass the results on to the writer process.
-    DocFun = fun
-        ({nil, Seq, _}, {SeqAcc, AccDel, AccNotDel}) ->
-            {erlang:max(Seq, SeqAcc), AccDel, AccNotDel};
-        ({Id, Seq, deleted}, {SeqAcc, AccDel, AccNotDel}) ->
-            {erlang:max(Seq, SeqAcc), [{Id, []} | AccDel], AccNotDel};
-        ({_Id, Seq, Doc}, {SeqAcc, AccDel, AccNotDel}) ->
-            {erlang:max(Seq, SeqAcc), AccDel, [Doc | AccNotDel]}
-    end,
-    FoldFun = fun(Docs, Acc) ->
-        lists:foldl(DocFun, Acc, Docs)
-    end,
-    {MaxSeq, DeletedResults, Docs} =
-        lists:foldl(FoldFun, {0, [], []}, Dequeued),
-    {ok, MapResultList} = couch_query_servers:map_docs_raw(Qs, Docs),
-    NotDeletedResults = lists:zipwith(
-        fun(#doc{id = Id}, MapResults) -> {Id, MapResults} end,
-        Docs,
-        MapResultList),
-    AllMapResults = DeletedResults ++ NotDeletedResults,
-    update_task(length(AllMapResults)),
-    {ok, {MaxSeq, AllMapResults}}.
-
-
 write_results(Parent, State) ->
     case couch_work_queue:dequeue(State#mrst.write_queue) of
         closed ->


[11/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
Fix whitespace


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/9f593394
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/9f593394
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/9f593394

Branch: refs/heads/import-rcouch
Commit: 9f593394c81790a87b7060e02c03d3dc8dd80163
Parents: e650b43
Author: Klaus Trainer <kl...@posteo.de>
Authored: Thu Nov 28 17:40:19 2013 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Nov 28 22:59:13 2013 +0000

----------------------------------------------------------------------
 src/couch_mrview_util.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/9f593394/src/couch_mrview_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_util.erl b/src/couch_mrview_util.erl
index a3b0581..c4272f8 100644
--- a/src/couch_mrview_util.erl
+++ b/src/couch_mrview_util.erl
@@ -540,7 +540,7 @@ delete_index_file(DbName, Sig) ->
 
 delete_compaction_file(DbName, Sig) ->
     delete_file(compaction_file(DbName, Sig)).
-    
+
 
 delete_file(FName) ->
     case filelib:is_file(FName) of


[09/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
Typo - no such function couch_httpd:send_method_not_allowd/2

Signed-off-by: Peter Lemenkov <le...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/f4739cd1
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/f4739cd1
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/f4739cd1

Branch: refs/heads/import-rcouch
Commit: f4739cd13bb1c8428db93bc5848e72aa9a47d6fb
Parents: fc01965
Author: Peter Lemenkov <le...@gmail.com>
Authored: Sat Aug 17 18:57:56 2013 +0400
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Aug 20 12:32:36 2013 +0100

----------------------------------------------------------------------
 src/couch_mrview_http.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/f4739cd1/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index 6e571f3..b8c4465 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -87,7 +87,7 @@ handle_compact_req(#httpd{method='POST'}=Req, Db, DDoc) ->
     ok = couch_mrview:compact(Db, DDoc),
     couch_httpd:send_json(Req, 202, {[{ok, true}]});
 handle_compact_req(Req, _Db, _DDoc) ->
-    couch_httpd:send_method_not_allowd(Req, "POST").
+    couch_httpd:send_method_not_allowed(Req, "POST").
 
 
 handle_cleanup_req(#httpd{method='POST'}=Req, Db) ->


[14/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
add index update events notifications


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/5dbbdb5f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/5dbbdb5f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/5dbbdb5f

Branch: refs/heads/import-rcouch
Commit: 5dbbdb5f81e1abe0b18cc94fc78e5c24721d8d62
Parents: c296d04
Author: benoitc <be...@apache.org>
Authored: Thu Jan 30 09:21:06 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Thu Feb 6 10:51:40 2014 -0600

----------------------------------------------------------------------
 src/couch_index_event.erl     | 65 ++++++++++++++++++++++++++++++++++++++
 src/couch_index_event_sup.erl | 51 ++++++++++++++++++++++++++++++
 src/couch_index_sup.erl       |  7 +++-
 3 files changed, 122 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/5dbbdb5f/src/couch_index_event.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_event.erl b/src/couch_index_event.erl
new file mode 100644
index 0000000..0cd0a6b
--- /dev/null
+++ b/src/couch_index_event.erl
@@ -0,0 +1,65 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_index_event).
+-behaviour(gen_event).
+
+-export([start_link/1]).
+-export([notify/1]).
+-export([stop/1]).
+
+%% gen_event callbacks
+-export([init/1, handle_event/2, handle_call/2, handle_info/2,
+         terminate/2, code_change/3]).
+
+start_link(Consumer) ->
+    HandlerId = {?MODULE, make_ref()},
+    couch_index_event_sup:start_link(couch_index_events, HandlerId,
+                                     Consumer).
+
+notify(Event) ->
+    gen_event:notify(couch_index_events, Event).
+
+stop(Pid) ->
+    couch_index_event_sup:stop(Pid).
+
+
+init(Consumer) ->
+    process_flag(trap_exit, true),
+    {ok, Consumer}.
+
+handle_event(Event, Consumer) ->
+    dispatch_event(Event, Consumer).
+
+handle_call(_Req, Consumer) ->
+    {reply, ok, Consumer}.
+
+handle_info({'EXIT', _, _}, _Consumer) ->
+    remove_handler;
+handle_info(_Info, Consumer)->
+    {ok, Consumer}.
+
+code_change(_OldVsn, Consumer, _Extra) ->
+    {ok, Consumer}.
+
+terminate(_Reason, _consumer) ->
+    ok.
+
+dispatch_event(Event, Fun) when is_function(Fun) ->
+    Fun(Event),
+    {ok, Fun};
+dispatch_event(Event, {Fun, Acc}) when is_function(Fun) ->
+    Acc2 = Fun(Event, Acc),
+    {ok, {Fun, Acc2}};
+dispatch_event(Event, Pid) when is_pid(Pid) ->
+    Pid ! Event,
+    {ok, Pid}.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/5dbbdb5f/src/couch_index_event_sup.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_event_sup.erl b/src/couch_index_event_sup.erl
new file mode 100644
index 0000000..68cba43
--- /dev/null
+++ b/src/couch_index_event_sup.erl
@@ -0,0 +1,51 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_index_event_sup).
+
+-export([start_link/3]).
+-export([stop/1]).
+
+%% internal gen_server callbacks
+-export([init/1, terminate/2, handle_call/3, handle_cast/2,
+         handle_info/2,code_change/3]).
+
+start_link(EventMgr, EventHandler, Args) ->
+    gen_server:start_link(?MODULE, {EventMgr, EventHandler, Args}, []).
+
+stop(Pid) ->
+    gen_server:cast(Pid, stop).
+
+init({EventMgr, EventHandler, Args}) ->
+    case gen_event:add_sup_handler(EventMgr, EventHandler, Args) of
+    ok ->
+        {ok, {EventMgr, EventHandler}};
+    {stop, Error} ->
+        {stop, Error}
+    end.
+
+handle_call(_Whatever, _From, State) ->
+    {ok, State}.
+
+handle_cast(stop, State) ->
+    {stop, normal, State}.
+
+handle_info({gen_event_EXIT, _Handler, Reason}, State) ->
+    {stop, Reason, State}.
+
+code_change(_OldVsn, State, _Extra) ->
+    {ok, State}.
+
+terminate(_Reason, _State) ->
+    ok.
+
+

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/5dbbdb5f/src/couch_index_sup.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_sup.erl b/src/couch_index_sup.erl
index fd97814..8e69016 100644
--- a/src/couch_index_sup.erl
+++ b/src/couch_index_sup.erl
@@ -26,4 +26,9 @@ start_link() ->
 
 init([]) ->
     Server = ?CHILD(couch_index_server),
-    {ok, {{one_for_one, 10, 3600}, [Server]}}.
+
+    EventSup = {couch_index_events,
+                {gen_event, start_link, [{local, couch_index_events}]},
+                permanent, brutal_kill, worker, dynamic},
+
+    {ok, {{one_for_one, 10, 3600}, [Server, EventSup]}}.


[08/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
add `users_db_public` config var


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/fc019651
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/fc019651
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/fc019651

Branch: refs/heads/import-rcouch
Commit: fc019651c8266ebf04eebdcb6b14d615651bb005
Parents: a4a72ba
Author: Jan Lehnardt <ja...@apache.org>
Authored: Wed Aug 7 15:45:16 2013 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Wed Aug 7 16:24:29 2013 +0200

----------------------------------------------------------------------
 src/couch_mrview_http.erl | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/fc019651/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index 61db4c0..6e571f3 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -111,12 +111,14 @@ all_docs_req(Req, Db, Keys) ->
                                   "authentication_db",
                                   "_users") of
             DbName ->
-                case couch_config:get("couch_httpd_auth", "public_fields") of
-                undefined ->
+                UsersDbPublic = couch_config:get("couch_httpd_auth", "users_db_public", "false"),
+                PublicFields = couch_config:get("couch_httpd_auth", "public_fields"),
+                case {UsersDbPublic, PublicFields} of
+                {"true", PublicFields} when PublicFields =/= undefined ->
+                    do_all_docs_req(Req, Db, Keys);
+                {_, _} ->
                     throw({forbidden, <<"Only admins can access _all_docs",
-                                        " of system databases.">>});
-                _ ->
-                    do_all_docs_req(Req, Db, Keys)
+                                        " of system databases.">>})
                 end;
             _ ->
                 throw({forbidden, <<"Only admins can access _all_docs",


[10/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
admins can always read all doc fields, regardless of public_fields

Closes COUCHDB-1888


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/f5c829fd
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/f5c829fd
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/f5c829fd

Branch: refs/heads/import-rcouch
Commit: f5c829fd69d355779b0fc2ebfde024ea76221f6f
Parents: f4739cd
Author: Jan Lehnardt <ja...@apache.org>
Authored: Wed Sep 25 17:40:14 2013 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Oct 3 17:58:25 2013 +0200

----------------------------------------------------------------------
 src/couch_mrview_http.erl | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/f5c829fd/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index b8c4465..8b914ef 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -129,7 +129,6 @@ all_docs_req(Req, Db, Keys) ->
         do_all_docs_req(Req, Db, Keys)
     end.
 
-
 do_all_docs_req(Req, Db, Keys) ->
     Args0 = parse_qs(Req, Keys),
     ETagFun = fun(Sig, Acc0) ->
@@ -143,14 +142,11 @@ do_all_docs_req(Req, Db, Keys) ->
     {ok, Resp} = couch_httpd:etag_maybe(Req, fun() ->
         VAcc0 = #vacc{db=Db, req=Req},
         DbName = ?b2l(Db#db.name),
-        Callback = case couch_config:get("couch_httpd_auth",
+        UsersDbName = couch_config:get("couch_httpd_auth",
                                          "authentication_db",
-                                         "_users") of
-        DbName ->
-            fun filtered_view_cb/2;
-        _ ->
-            fun view_cb/2
-        end,
+                                         "_users"),
+        IsAdmin = is_admin(Db),
+        Callback = get_view_callback(DbName, UsersDbName, IsAdmin),
         couch_mrview:query_all_docs(Db, Args, Callback, VAcc0)
     end),
     case is_record(Resp, vacc) of
@@ -158,6 +154,26 @@ do_all_docs_req(Req, Db, Keys) ->
         _ -> {ok, Resp}
     end.
 
+is_admin(Db) ->
+    case catch couch_db:check_is_admin(Db) of
+    {unauthorized, _} ->
+        false;
+    ok ->
+        true
+    end.
+
+
+% admin users always get all fields
+get_view_callback(_, _, true) ->
+    fun view_cb/2;
+% if we are operating on the users db and we aren't
+% admin, filter the view
+get_view_callback(_DbName, _DbName, false) ->
+    fun filtered_view_cb/2;
+% non _users databases get all fields
+get_view_callback(_, _, _) ->
+    fun view_cb/2.
+
 
 design_doc_view(Req, Db, DDoc, ViewName, Keys) ->
     Args0 = parse_qs(Req, Keys),


[20/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
couch_mrview: couch_mrview_changes:handle_changes

Similar to couch_changes:handle_changes but for view changes. It add
support for longpolling, normal and continuous stream The API differs
from the one for doc by beeing independant from the transport: the
support of HTTP will be added on top for example.

This API will be also used to replace the view filter in the current _changes
API.

Also add unittests.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/b60ac211
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/b60ac211
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/b60ac211

Branch: refs/heads/import-rcouch
Commit: b60ac211ca7b162048dc88bbf4da75c3c926a8d6
Parents: 5dbbdb5
Author: benoitc <be...@apache.org>
Authored: Fri Jan 31 13:13:23 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Thu Feb 6 10:51:40 2014 -0600

----------------------------------------------------------------------
 src/couch_index_server.erl | 7 +++++++
 1 file changed, 7 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/b60ac211/src/couch_index_server.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_server.erl b/src/couch_index_server.erl
index 86791db..facde14 100644
--- a/src/couch_index_server.erl
+++ b/src/couch_index_server.erl
@@ -159,6 +159,8 @@ reset_indexes(DbName, Root) ->
         MRef = erlang:monitor(process, Pid),
         gen_server:cast(Pid, delete),
         receive {'DOWN', MRef, _, _, _} -> ok end,
+        couch_index_event:notify({index_delete,
+                                  {DbName, DDocId, couch_mrview_index}}),
         rem_from_ets(DbName, Sig, DDocId, Pid)
     end,
     lists:foreach(Fun, ets:lookup(?BY_DB, DbName)),
@@ -193,6 +195,11 @@ update_notify({ddoc_updated, {DbName, DDocId}}) ->
         fun({_DbName, {_DDocId, Sig}}) ->
             case ets:lookup(?BY_SIG, {DbName, Sig}) of
                 [{_, IndexPid}] ->
+                    %% notify to event listeners that the index has been
+                    %% updated
+                    couch_index_event:notify({index_update,
+                                              {DbName, DDocId,
+                                               couch_mrview_index}}),
                     (catch gen_server:cast(IndexPid, ddoc_updated));
                 [] ->
                     ok


[06/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
Apply _list functions for _all_docs view. COUCHDB-1139


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/246048dd
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/246048dd
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/246048dd

Branch: refs/heads/import-rcouch
Commit: 246048ddd612322713ad4530104aabd5c1141ed3
Parents: 3651497
Author: Alexander Shorin <kx...@apache.org>
Authored: Wed Jul 24 18:12:03 2013 +0400
Committer: Alexander Shorin <kx...@apache.org>
Committed: Wed Jul 24 18:12:03 2013 +0400

----------------------------------------------------------------------
 src/couch_mrview_show.erl | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/246048dd/src/couch_mrview_show.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_show.erl b/src/couch_mrview_show.erl
index 98b2d63..f8fa837 100644
--- a/src/couch_mrview_show.erl
+++ b/src/couch_mrview_show.erl
@@ -210,7 +210,12 @@ handle_view_list(Req, Db, DDoc, LName, VDDoc, VName, Keys) ->
     couch_httpd:etag_maybe(Req, fun() ->
         couch_query_servers:with_ddoc_proc(DDoc, fun(QServer) ->
             Acc = #lacc{db=Db, req=Req, qserver=QServer, lname=LName},
-            couch_mrview:query_view(Db, VDDoc, VName, Args, fun list_cb/2, Acc)
+            case VName of
+              <<"_all_docs">> ->
+                couch_mrview:query_all_docs(Db, Args, fun list_cb/2, Acc);
+              _ ->
+                couch_mrview:query_view(Db, VDDoc, VName, Args, fun list_cb/2, Acc)
+            end
         end)
     end).
 


[07/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
Merge remote-tracking branch 'origin/1334-revert-feature-view-server-pipelining'


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/a4a72ba0
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/a4a72ba0
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/a4a72ba0

Branch: refs/heads/import-rcouch
Commit: a4a72ba0fdf7b90ce6dd348d289a0e7617bae06e
Parents: 246048d ad50fe9
Author: Dirkjan Ochtman <dj...@apache.org>
Authored: Sat Aug 3 17:37:37 2013 +0200
Committer: Dirkjan Ochtman <dj...@apache.org>
Committed: Sat Aug 3 17:37:37 2013 +0200

----------------------------------------------------------------------
 src/couch_mrview_updater.erl | 46 +++++++++++++++------------------------
 1 file changed, 18 insertions(+), 28 deletions(-)
----------------------------------------------------------------------



[02/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
COUCHDB-1654: Transparently update view signatures from <= 1.2.x.

Updates 1.2.x or earlier view files to 1.3.x or later view files
transparently, the first time the 1.2.x view file is opened by
1.3.x or later.

Here's how it works:

Before opening a view index,
If no matching index file is found in the new location:
 calculate the <= 1.2.x view signature
 if a file with that signature lives in the old location
   copy it to the new location with the new signature in the name.
Then proceed to open the view index as usual.
After opening, read its header.

If the header matches the <= 1.2.x style #index_header record:
  upgrade the header to the new #mrheader record
The next time the view is used, the new header is used.

If we crash after the rename, but before the header upgrade,
  the header upgrade is done on the next view opening.

If we crash between upgrading to the new header and writing
  that header to disk, we start with the old header again,
  do the upgrade and write to disk.

Includes etap tests in 250*.t.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/0e28dfc5
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/0e28dfc5
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/0e28dfc5

Branch: refs/heads/import-rcouch
Commit: 0e28dfc52a37ee555862bd12e41d107ea20439e2
Parents: cab082b
Author: Jan Lehnardt <ja...@apache.org>
Authored: Mon Feb 4 15:29:17 2013 +0100
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Wed Feb 6 22:52:09 2013 +0100

----------------------------------------------------------------------
 src/couch_mrview_index.erl |  21 +++++++++
 src/couch_mrview_util.erl  | 101 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 122 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/0e28dfc5/src/couch_mrview_index.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_index.erl b/src/couch_mrview_index.erl
index 6bcb63f..7466dbc 100644
--- a/src/couch_mrview_index.erl
+++ b/src/couch_mrview_index.erl
@@ -75,9 +75,30 @@ open(Db, State) ->
         sig=Sig
     } = State,
     IndexFName = couch_mrview_util:index_file(DbName, Sig),
+
+    % If we are upgrading from <=1.2.x, we upgrade the view
+    % index file on the fly, avoiding an index reset.
+    %
+    % OldSig is `ok` if no upgrade happened.
+    %
+    % To remove suppport for 1.2.x auto-upgrades in the
+    % future, just remove the next line and the code
+    % between "upgrade code for <= 1.2.x" and
+    % "end upgrade code for <= 1.2.x" and the corresponding
+    % code in couch_mrview_util
+
+    OldSig = couch_mrview_util:maybe_update_index_file(State),
+
     case couch_mrview_util:open_file(IndexFName) of
         {ok, Fd} ->
             case (catch couch_file:read_header(Fd)) of
+                % upgrade code for <= 1.2.x
+                {ok, {OldSig, Header}} ->
+                    % Matching view signatures.
+                    NewSt = couch_mrview_util:init_state(Db, Fd, State, Header),
+                    {ok, RefCounter} = couch_ref_counter:start([Fd]),
+                    {ok, NewSt#mrst{refc=RefCounter}};
+                % end of upgrade code for <= 1.2.x
                 {ok, {Sig, Header}} ->
                     % Matching view signatures.
                     NewSt = couch_mrview_util:init_state(Db, Fd, State, Header),

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/0e28dfc5/src/couch_mrview_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_util.erl b/src/couch_mrview_util.erl
index 8e6e4dc..092ae3d 100644
--- a/src/couch_mrview_util.erl
+++ b/src/couch_mrview_util.erl
@@ -24,6 +24,7 @@
 -export([calculate_data_size/2]).
 -export([validate_args/1]).
 -export([maybe_load_doc/3, maybe_load_doc/4]).
+-export([maybe_update_index_file/1]).
 
 -define(MOD, couch_mrview_index).
 
@@ -168,6 +169,19 @@ init_state(Db, Fd, #mrst{views=Views}=State, nil) ->
         view_states=[{nil, 0, 0} || _ <- Views]
     },
     init_state(Db, Fd, State, Header);
+% read <= 1.2.x header record and transpile it to >=1.3.x
+% header record
+init_state(Db, Fd, State, #index_header{
+    seq=Seq,
+    purge_seq=PurgeSeq,
+    id_btree_state=IdBtreeState,
+    view_states=ViewStates}) ->
+    init_state(Db, Fd, State, #mrheader{
+        seq=Seq,
+        purge_seq=PurgeSeq,
+        id_btree_state=IdBtreeState,
+        view_states=ViewStates
+        });
 init_state(Db, Fd, State, Header) ->
     #mrst{language=Lang, views=Views} = State,
     #mrheader{
@@ -704,3 +718,90 @@ index_of(Key, [_ | Rest], Idx) ->
 
 mrverror(Mesg) ->
     throw({query_parse_error, Mesg}).
+
+
+%% Updates 1.2.x or earlier view files to 1.3.x or later view files
+%% transparently, the first time the 1.2.x view file is opened by
+%% 1.3.x or later.
+%%
+%% Here's how it works:
+%%
+%% Before opening a view index,
+%% If no matching index file is found in the new location:
+%%  calculate the <= 1.2.x view signature
+%%  if a file with that signature lives in the old location
+%%    rename it to the new location with the new signature in the name.
+%% Then proceed to open the view index as usual.
+%% After opening, read its header.
+%%
+%% If the header matches the <= 1.2.x style #index_header record:
+%%   upgrade the header to the new #mrheader record
+%% The next time the view is used, the new header is used.
+%%
+%% If we crash after the rename, but before the header upgrade,
+%%   the header upgrade is done on the next view opening.
+%%
+%% If we crash between upgrading to the new header and writing
+%%   that header to disk, we start with the old header again,
+%%   do the upgrade and write to disk.
+
+maybe_update_index_file(State) ->
+    DbName = State#mrst.db_name,
+    NewIndexFile = index_file(DbName, State#mrst.sig),
+    % open in read-only mode so we don't create
+    % the file if it doesn't exist.
+    case file:open(NewIndexFile, [read, raw]) of
+    {ok, Fd_Read} ->
+        % the new index file exists, there is nothing to do here.
+        file:close(Fd_Read);
+    _Error ->
+        update_index_file(State)
+    end.
+
+update_index_file(State) ->
+    Sig = sig_vsn_12x(State),
+    DbName = State#mrst.db_name,
+    FileName = couch_index_util:hexsig(Sig) ++ ".view",
+    IndexFile = couch_index_util:index_file("", DbName, FileName),
+
+    % If we have an old index, rename it to the new position.
+    case file:read_file_info(IndexFile) of
+    {ok, _FileInfo} ->
+        % Crash if the rename fails for any reason.
+        % If the target exists, e.g. the next request will find the
+        % new file and we are good. We might need to catch this
+        % further up to avoid a full server crash.
+        ?LOG_INFO("Attempting to update legacy view index file.", []),
+        NewIndexFile = index_file(DbName, State#mrst.sig),
+        ok = filelib:ensure_dir(NewIndexFile),
+        ok = file:rename(IndexFile, NewIndexFile),
+        ?LOG_INFO("Successfully updated legacy view index file.", []),
+        Sig;
+    _ ->
+        % Ignore missing index file
+        ok
+    end.
+
+sig_vsn_12x(State) ->
+    ViewInfo = [old_view_format(V) || V <- State#mrst.views],
+    SigData = case State#mrst.lib of
+    {[]} ->
+        {ViewInfo, State#mrst.language, State#mrst.design_opts};
+    _ ->
+        {ViewInfo, State#mrst.language, State#mrst.design_opts,
+            couch_index_util:sort_lib(State#mrst.lib)}
+    end,
+    couch_util:md5(term_to_binary(SigData)).
+
+old_view_format(View) ->
+{
+    view,
+    View#mrview.id_num,
+    View#mrview.map_names,
+    View#mrview.def,
+    View#mrview.btree,
+    View#mrview.reduce_funs,
+    View#mrview.options
+}.
+
+%% End of <= 1.2.x upgrade code.


[18/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
couch_index_sup should be started by the couch application

I had this patch landing in a custommer repository for awhile. Since
couch_index is always dependent of couch it's better to add it to the
couch application supervision rather than on its own.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/bce80b4f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/bce80b4f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/bce80b4f

Branch: refs/heads/import-rcouch
Commit: bce80b4f704359ec77fc3af732c352ab4c136be6
Parents: 2de6fb4
Author: benoitc <be...@apache.org>
Authored: Thu Jan 9 23:29:54 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Thu Feb 6 10:51:40 2014 -0600

----------------------------------------------------------------------
 test/02-map-views.t    | 2 --
 test/03-red-views.t    | 1 -
 test/04-index-info.t   | 1 -
 test/05-collation.t    | 1 -
 test/06-all-docs.t     | 1 -
 test/07-compact-swap.t | 1 -
 6 files changed, 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/bce80b4f/test/02-map-views.t
----------------------------------------------------------------------
diff --git a/test/02-map-views.t b/test/02-map-views.t
index ed1b1cc..567042d 100644
--- a/test/02-map-views.t
+++ b/test/02-map-views.t
@@ -30,8 +30,6 @@ main(_) ->
 
 test() ->
     couch_server_sup:start_link(test_util:config_files()),
-    couch_index_sup:start_link(),
-
     {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, map),
 
     test_basic(Db),

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/bce80b4f/test/03-red-views.t
----------------------------------------------------------------------
diff --git a/test/03-red-views.t b/test/03-red-views.t
index 17b9148..7f52f75 100644
--- a/test/03-red-views.t
+++ b/test/03-red-views.t
@@ -20,7 +20,6 @@ main(_) ->
 
 test() ->
     couch_server_sup:start_link(test_util:config_files()),
-    couch_index_sup:start_link(),
 
     {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, red),
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/bce80b4f/test/04-index-info.t
----------------------------------------------------------------------
diff --git a/test/04-index-info.t b/test/04-index-info.t
index 73c4dcc..834b7d2 100644
--- a/test/04-index-info.t
+++ b/test/04-index-info.t
@@ -32,7 +32,6 @@ sig() -> <<"276df562b152b3c4e5d34024f62672ed">>.
 
 test() ->
     couch_server_sup:start_link(test_util:config_files()),
-    couch_index_sup:start_link(),
 
     {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, map),
     couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/bce80b4f/test/05-collation.t
----------------------------------------------------------------------
diff --git a/test/05-collation.t b/test/05-collation.t
index d476601..f98e88d 100644
--- a/test/05-collation.t
+++ b/test/05-collation.t
@@ -20,7 +20,6 @@ main(_) ->
 
 test() ->
     couch_server_sup:start_link(test_util:config_files()),
-    couch_index_sup:start_link(),
 
     {ok, Db0} = couch_mrview_test_util:new_db(<<"foo">>, map),
     {ok, Db1} = couch_mrview_test_util:save_docs(Db0, docs()),

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/bce80b4f/test/06-all-docs.t
----------------------------------------------------------------------
diff --git a/test/06-all-docs.t b/test/06-all-docs.t
index a19cd7e..370825e 100644
--- a/test/06-all-docs.t
+++ b/test/06-all-docs.t
@@ -20,7 +20,6 @@ main(_) ->
 
 test() ->
     couch_server_sup:start_link(test_util:config_files()),
-    couch_index_sup:start_link(),
 
     {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, map),
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/bce80b4f/test/07-compact-swap.t
----------------------------------------------------------------------
diff --git a/test/07-compact-swap.t b/test/07-compact-swap.t
index a74d273..f7ebca2 100644
--- a/test/07-compact-swap.t
+++ b/test/07-compact-swap.t
@@ -21,7 +21,6 @@ main(_) ->
 
 test() ->
     couch_server_sup:start_link(test_util:config_files()),
-    couch_index_sup:start_link(),
 
     {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, map, 1000),
     couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),


[16/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
inital move to rebar compilation

- move src/apps
- download dependencies using rebar
- replace ejson by jiffy
- replace couch_drv & couch_ejson_compare by couch_collate


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/55874fbc
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/55874fbc
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/55874fbc

Branch: refs/heads/import-rcouch
Commit: 55874fbca54a4e238839a4782eb822f0eae1d347
Parents: 9f59339
Author: benoitc <be...@apache.org>
Authored: Mon Jan 6 21:12:45 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Thu Feb 6 10:51:40 2014 -0600

----------------------------------------------------------------------
 src/couch_mrview.erl           | 2 +-
 src/couch_mrview_cleanup.erl   | 4 +---
 src/couch_mrview_compactor.erl | 4 ++--
 src/couch_mrview_http.erl      | 3 +--
 src/couch_mrview_index.erl     | 2 +-
 src/couch_mrview_show.erl      | 2 +-
 src/couch_mrview_test_util.erl | 3 ++-
 src/couch_mrview_updater.erl   | 2 +-
 src/couch_mrview_util.erl      | 2 +-
 9 files changed, 11 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/55874fbc/src/couch_mrview.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview.erl b/src/couch_mrview.erl
index 2964fe9..d31ed18 100644
--- a/src/couch_mrview.erl
+++ b/src/couch_mrview.erl
@@ -18,7 +18,7 @@
 -export([compact/2, compact/3, cancel_compaction/2]).
 -export([cleanup/1]).
 
--include("couch_db.hrl").
+-include_lib("couch/include/couch_db.hrl").
 -include_lib("couch_mrview/include/couch_mrview.hrl").
 
 -record(mracc, {

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/55874fbc/src/couch_mrview_cleanup.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_cleanup.erl b/src/couch_mrview_cleanup.erl
index d48de6f..c94b9f8 100644
--- a/src/couch_mrview_cleanup.erl
+++ b/src/couch_mrview_cleanup.erl
@@ -14,11 +14,9 @@
 
 -export([run/1]).
 
-
--include("couch_db.hrl").
+-include_lib("couch/include/couch_db.hrl").
 -include_lib("couch_mrview/include/couch_mrview.hrl").
 
-
 run(Db) ->
     RootDir = couch_index_util:root_dir(),
     DbName = couch_db:name(Db),

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/55874fbc/src/couch_mrview_compactor.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_compactor.erl b/src/couch_mrview_compactor.erl
index fe718ca..4ab8dd1 100644
--- a/src/couch_mrview_compactor.erl
+++ b/src/couch_mrview_compactor.erl
@@ -12,7 +12,7 @@
 
 -module(couch_mrview_compactor).
 
--include("couch_db.hrl").
+-include_lib("couch/include/couch_db.hrl").
 -include_lib("couch_mrview/include/couch_mrview.hrl").
 
 -export([compact/3, swap_compacted/2]).
@@ -174,5 +174,5 @@ swap_compacted(OldState, NewState) ->
     unlink(OldState#mrst.fd),
     couch_ref_counter:drop(OldState#mrst.refc),
     {ok, NewRefCounter} = couch_ref_counter:start([NewState#mrst.fd]),
-    
+
     {ok, NewState#mrst{refc=NewRefCounter}}.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/55874fbc/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index 7b92034..22e0dc3 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -22,8 +22,7 @@
     parse_qs/2
 ]).
 
-
--include("couch_db.hrl").
+-include_lib("couch/include/couch_db.hrl").
 -include_lib("couch_mrview/include/couch_mrview.hrl").
 
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/55874fbc/src/couch_mrview_index.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_index.erl b/src/couch_mrview_index.erl
index 7466dbc..7506f34 100644
--- a/src/couch_mrview_index.erl
+++ b/src/couch_mrview_index.erl
@@ -18,7 +18,7 @@
 -export([start_update/3, purge/4, process_doc/3, finish_update/1, commit/1]).
 -export([compact/3, swap_compacted/2]).
 
--include("couch_db.hrl").
+-include_lib("couch/include/couch_db.hrl").
 -include_lib("couch_mrview/include/couch_mrview.hrl").
 
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/55874fbc/src/couch_mrview_show.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_show.erl b/src/couch_mrview_show.erl
index f8fa837..4ab8e17 100644
--- a/src/couch_mrview_show.erl
+++ b/src/couch_mrview_show.erl
@@ -18,7 +18,7 @@
     handle_view_list_req/3
 ]).
 
--include("couch_db.hrl").
+-include_lib("couch/include/couch_db.hrl").
 -include_lib("couch_mrview/include/couch_mrview.hrl").
 
 -record(lacc, {

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/55874fbc/src/couch_mrview_test_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_test_util.erl b/src/couch_mrview_test_util.erl
index 338ae38..adc2675 100644
--- a/src/couch_mrview_test_util.erl
+++ b/src/couch_mrview_test_util.erl
@@ -14,7 +14,8 @@
 
 -compile(export_all).
 
--include("couch_db.hrl").
+-include_lib("couch/include/couch_db.hrl").
+
 -define(ADMIN, #user_ctx{roles=[<<"_admin">>]}).
 
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/55874fbc/src/couch_mrview_updater.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_updater.erl b/src/couch_mrview_updater.erl
index 9604ea9..980b5cf 100644
--- a/src/couch_mrview_updater.erl
+++ b/src/couch_mrview_updater.erl
@@ -14,7 +14,7 @@
 
 -export([start_update/3, purge/4, process_doc/3, finish_update/1]).
 
--include("couch_db.hrl").
+-include_lib("couch/include/couch_db.hrl").
 -include_lib("couch_mrview/include/couch_mrview.hrl").
 
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/55874fbc/src/couch_mrview_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_util.erl b/src/couch_mrview_util.erl
index c4272f8..f7946d1 100644
--- a/src/couch_mrview_util.erl
+++ b/src/couch_mrview_util.erl
@@ -28,7 +28,7 @@
 
 -define(MOD, couch_mrview_index).
 
--include("couch_db.hrl").
+-include_lib("couch/include/couch_db.hrl").
 -include_lib("couch_mrview/include/couch_mrview.hrl").
 
 


[17/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
move src/* to the root

There is no need of an src/ folder except for an aesthetic reason, we
are obviously distributing a source. This layout is alos more common in
the Erlang world, and most editor and package manager understand it.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/c296d042
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/c296d042
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/c296d042

Branch: refs/heads/import-rcouch
Commit: c296d04294614e3172c39afa1b4174580e24ff2d
Parents: 5813a97
Author: benoitc <be...@apache.org>
Authored: Sun Jan 12 10:17:31 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Thu Feb 6 10:51:40 2014 -0600

----------------------------------------------------------------------
 src/couch_index.app.src       |  19 +++
 src/couch_index.erl           | 338 +++++++++++++++++++++++++++++++++++++
 src/couch_index_api.erl       |  54 ++++++
 src/couch_index_compactor.erl | 113 +++++++++++++
 src/couch_index_server.erl    | 203 ++++++++++++++++++++++
 src/couch_index_sup.erl       |  29 ++++
 src/couch_index_updater.erl   | 200 ++++++++++++++++++++++
 src/couch_index_util.erl      |  77 +++++++++
 8 files changed, 1033 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/c296d042/src/couch_index.app.src
----------------------------------------------------------------------
diff --git a/src/couch_index.app.src b/src/couch_index.app.src
new file mode 100644
index 0000000..921e5d2
--- /dev/null
+++ b/src/couch_index.app.src
@@ -0,0 +1,19 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+{application, couch_index, [
+    {description, "CouchDB Secondary Index Manager"},
+    {vsn, "1.3.0"},
+    {modules, []},
+    {registered, [couch_index_server]},
+    {applications, [kernel, stdlib, couch]}
+]}.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/c296d042/src/couch_index.erl
----------------------------------------------------------------------
diff --git a/src/couch_index.erl b/src/couch_index.erl
new file mode 100644
index 0000000..c09a110
--- /dev/null
+++ b/src/couch_index.erl
@@ -0,0 +1,338 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_index).
+-behaviour(gen_server).
+
+
+%% API
+-export([start_link/1, stop/1, get_state/2, get_info/1]).
+-export([compact/1, compact/2, get_compactor_pid/1]).
+-export([config_change/3]).
+
+%% gen_server callbacks
+-export([init/1, terminate/2, code_change/3]).
+-export([handle_call/3, handle_cast/2, handle_info/2]).
+
+-include_lib("couch/include/couch_db.hrl").
+
+-record(st, {
+    mod,
+    idx_state,
+    updater,
+    compactor,
+    waiters=[],
+    commit_delay,
+    committed=true,
+    shutdown=false
+}).
+
+
+start_link({Module, IdxState}) ->
+    proc_lib:start_link(?MODULE, init, [{Module, IdxState}]).
+
+
+stop(Pid) ->
+    gen_server:cast(Pid, stop).
+
+
+get_state(Pid, RequestSeq) ->
+    gen_server:call(Pid, {get_state, RequestSeq}, infinity).
+
+
+get_info(Pid) ->
+    gen_server:call(Pid, get_info).
+
+
+compact(Pid) ->
+    compact(Pid, []).
+
+
+compact(Pid, Options) ->
+    {ok, CPid} = gen_server:call(Pid, compact),
+    case lists:member(monitor, Options) of
+        true -> {ok, erlang:monitor(process, CPid)};
+        false -> ok
+    end.
+
+
+get_compactor_pid(Pid) ->
+    gen_server:call(Pid, get_compactor_pid).
+
+config_change("query_server_config", "commit_freq", NewValue) ->
+    ok = gen_server:cast(?MODULE, {config_update, NewValue}).
+
+
+init({Mod, IdxState}) ->
+    ok = couch_config:register(fun ?MODULE:config_change/3),
+    DbName = Mod:get(db_name, IdxState),
+    Resp = couch_util:with_db(DbName, fun(Db) ->
+        case Mod:open(Db, IdxState) of
+            {ok, IdxSt} ->
+                couch_db:monitor(Db),
+                {ok, IdxSt};
+            Error ->
+                Error
+        end
+    end),
+    case Resp of
+        {ok, NewIdxState} ->
+            {ok, UPid} = couch_index_updater:start_link(self(), Mod),
+            {ok, CPid} = couch_index_compactor:start_link(self(), Mod),
+            Delay = couch_config:get("query_server_config", "commit_freq", "5"),
+            MsDelay = 1000 * list_to_integer(Delay),
+            State = #st{
+                mod=Mod,
+                idx_state=NewIdxState,
+                updater=UPid,
+                compactor=CPid,
+                commit_delay=MsDelay
+            },
+            Args = [
+                Mod:get(db_name, IdxState),
+                Mod:get(idx_name, IdxState),
+                couch_index_util:hexsig(Mod:get(signature, IdxState))
+            ],
+            ?LOG_INFO("Opening index for db: ~s idx: ~s sig: ~p", Args),
+            proc_lib:init_ack({ok, self()}),
+            gen_server:enter_loop(?MODULE, [], State);
+        Other ->
+            proc_lib:init_ack(Other)
+    end.
+
+
+terminate(Reason, State) ->
+    #st{mod=Mod, idx_state=IdxState}=State,
+    Mod:close(IdxState),
+    send_all(State#st.waiters, Reason),
+    couch_util:shutdown_sync(State#st.updater),
+    couch_util:shutdown_sync(State#st.compactor),
+    Args = [
+        Mod:get(db_name, IdxState),
+        Mod:get(idx_name, IdxState),
+        couch_index_util:hexsig(Mod:get(signature, IdxState)),
+        Reason
+    ],
+    ?LOG_INFO("Closing index for db: ~s idx: ~s sig: ~p~nreason: ~p", Args),
+    ok.
+
+
+handle_call({get_state, ReqSeq}, From, State) ->
+    #st{
+        mod=Mod,
+        idx_state=IdxState,
+        waiters=Waiters
+    } = State,
+    IdxSeq = Mod:get(update_seq, IdxState),
+    case ReqSeq =< IdxSeq of
+        true ->
+            {reply, {ok, IdxState}, State};
+        _ -> % View update required
+            couch_index_updater:run(State#st.updater, IdxState),
+            Waiters2 = [{From, ReqSeq} | Waiters],
+            {noreply, State#st{waiters=Waiters2}, infinity}
+    end;
+handle_call(get_info, _From, State) ->
+    #st{mod=Mod} = State,
+    {ok, Info0} = Mod:get(info, State#st.idx_state),
+    IsUpdating = couch_index_updater:is_running(State#st.updater),
+    IsCompacting = couch_index_compactor:is_running(State#st.compactor),
+    Info = Info0 ++ [
+        {updater_running, IsUpdating},
+        {compact_running, IsCompacting},
+        {waiting_commit, State#st.committed == false},
+        {waiting_clients, length(State#st.waiters)}
+    ],
+    {reply, {ok, Info}, State};
+handle_call(reset, _From, State) ->
+    #st{
+        mod=Mod,
+        idx_state=IdxState
+    } = State,
+    {ok, NewIdxState} = Mod:reset(IdxState),
+    {reply, {ok, NewIdxState}, State#st{idx_state=NewIdxState}};
+handle_call(compact, _From, State) ->
+    Resp = couch_index_compactor:run(State#st.compactor, State#st.idx_state),
+    {reply, Resp, State};
+handle_call(get_compactor_pid, _From, State) ->
+    {reply, {ok, State#st.compactor}, State};
+handle_call({compacted, NewIdxState}, _From, State) ->
+    #st{
+        mod=Mod,
+        idx_state=OldIdxState,
+        updater=Updater,
+        commit_delay=Delay
+    } = State,
+    assert_signature_match(Mod, OldIdxState, NewIdxState),
+    NewSeq = Mod:get(update_seq, NewIdxState),
+    OldSeq = Mod:get(update_seq, OldIdxState),
+    % For indices that require swapping files, we have to make sure we're
+    % up to date with the current index. Otherwise indexes could roll back
+    % (perhaps considerably) to previous points in history.
+    case NewSeq >= OldSeq of
+        true ->
+            {ok, NewIdxState1} = Mod:swap_compacted(OldIdxState, NewIdxState),
+            % Restart the indexer if it's running.
+            case couch_index_updater:is_running(Updater) of
+                true -> ok = couch_index_updater:restart(Updater, NewIdxState1);
+                false -> ok
+            end,
+            case State#st.committed of
+                true -> erlang:send_after(Delay, self(), commit);
+                false -> ok
+            end,
+            {reply, ok, State#st{
+                idx_state=NewIdxState1,
+                committed=false
+            }};
+        _ ->
+            {reply, recompact, State}
+    end.
+
+
+handle_cast({config_change, NewDelay}, State) ->
+    MsDelay = 1000 * list_to_integer(NewDelay),
+    {noreply, State#st{commit_delay=MsDelay}};
+handle_cast({updated, NewIdxState}, State) ->
+    {noreply, NewState} = handle_cast({new_state, NewIdxState}, State),
+    case NewState#st.shutdown andalso (NewState#st.waiters =:= []) of
+        true ->
+            {stop, normal, NewState};
+        false ->
+            maybe_restart_updater(NewState),
+            {noreply, NewState}
+    end;
+handle_cast({new_state, NewIdxState}, State) ->
+    #st{
+        mod=Mod,
+        idx_state=OldIdxState,
+        commit_delay=Delay
+    } = State,
+    assert_signature_match(Mod, OldIdxState, NewIdxState),
+    CurrSeq = Mod:get(update_seq, NewIdxState),
+    Args = [
+        Mod:get(db_name, NewIdxState),
+        Mod:get(idx_name, NewIdxState),
+        CurrSeq
+    ],
+    ?LOG_DEBUG("Updated index for db: ~s idx: ~s seq: ~B", Args),
+    Rest = send_replies(State#st.waiters, CurrSeq, NewIdxState),
+    case State#st.committed of
+        true -> erlang:send_after(Delay, self(), commit);
+        false -> ok
+    end,
+    {noreply, State#st{
+        idx_state=NewIdxState,
+        waiters=Rest,
+        committed=false
+    }};
+handle_cast({update_error, Error}, State) ->
+    send_all(State#st.waiters, Error),
+    {noreply, State#st{waiters=[]}};
+handle_cast(stop, State) ->
+    {stop, normal, State};
+handle_cast(delete, State) ->
+    #st{mod=Mod, idx_state=IdxState} = State,
+    ok = Mod:delete(IdxState),
+    {stop, normal, State};
+handle_cast(ddoc_updated, State) ->
+    #st{mod = Mod, idx_state = IdxState, waiters = Waiters} = State,
+    DbName = Mod:get(db_name, IdxState),
+    DDocId = Mod:get(idx_name, IdxState),
+    Shutdown = couch_util:with_db(DbName, fun(Db) ->
+        case couch_db:open_doc(Db, DDocId, [ejson_body]) of
+            {not_found, deleted} ->
+                true;
+            {ok, DDoc} ->
+                {ok, NewIdxState} = Mod:init(Db, DDoc),
+                Mod:get(signature, NewIdxState) =/= Mod:get(signature, IdxState)
+        end
+    end),
+    case Shutdown of
+        true ->
+            case Waiters of
+                [] ->
+                    {stop, normal, State};
+                _ ->
+                    {noreply, State#st{shutdown = true}}
+            end;
+        false ->
+            {noreply, State#st{shutdown = false}}
+    end;
+handle_cast(_Mesg, State) ->
+    {stop, unhandled_cast, State}.
+
+
+handle_info(commit, #st{committed=true}=State) ->
+    {noreply, State};
+handle_info(commit, State) ->
+    #st{mod=Mod, idx_state=IdxState, commit_delay=Delay} = State,
+    DbName = Mod:get(db_name, IdxState),
+    GetCommSeq = fun(Db) -> couch_db:get_committed_update_seq(Db) end,
+    CommittedSeq = couch_util:with_db(DbName, GetCommSeq),
+    case CommittedSeq >= Mod:get(update_seq, IdxState) of
+        true ->
+            % Commit the updates
+            ok = Mod:commit(IdxState),
+            {noreply, State#st{committed=true}};
+        _ ->
+            % We can't commit the header because the database seq that's
+            % fully committed to disk is still behind us. If we committed
+            % now and the database lost those changes our view could be
+            % forever out of sync with the database. But a crash before we
+            % commit these changes, no big deal, we only lose incremental
+            % changes since last committal.
+            erlang:send_after(Delay, self(), commit),
+            {noreply, State}
+    end;
+handle_info({'DOWN', _, _, _Pid, _}, #st{mod=Mod, idx_state=IdxState}=State) ->
+    Args = [Mod:get(db_name, IdxState), Mod:get(idx_name, IdxState)],
+    ?LOG_INFO("Index shutdown by monitor notice for db: ~s idx: ~s", Args),
+    catch send_all(State#st.waiters, shutdown),
+    {stop, normal, State#st{waiters=[]}}.
+
+
+code_change(_OldVsn, State, _Extra) ->
+    {ok, State}.
+
+
+maybe_restart_updater(#st{waiters=[]}) ->
+    ok;
+maybe_restart_updater(#st{mod=Mod, idx_state=IdxState}=State) ->
+    couch_util:with_db(Mod:get(db_name, IdxState), fun(Db) ->
+        UpdateSeq = couch_db:get_update_seq(Db),
+        CommittedSeq = couch_db:get_committed_update_seq(Db),
+        CanUpdate = UpdateSeq > CommittedSeq,
+        UOpts = Mod:get(update_options, IdxState),
+        case CanUpdate and lists:member(committed_only, UOpts) of
+            true -> couch_db:ensure_full_commit(Db);
+            false -> ok
+        end
+    end),
+    couch_index_updater:run(State#st.updater, IdxState).
+
+
+send_all(Waiters, Reply) ->
+    [gen_server:reply(From, Reply) || {From, _} <- Waiters].
+
+
+send_replies(Waiters, UpdateSeq, IdxState) ->
+    Pred = fun({_, S}) -> S =< UpdateSeq end,
+    {ToSend, Remaining} = lists:partition(Pred, Waiters),
+    [gen_server:reply(From, {ok, IdxState}) || {From, _} <- ToSend],
+    Remaining.
+
+assert_signature_match(Mod, OldIdxState, NewIdxState) ->
+    case {Mod:get(signature, OldIdxState), Mod:get(signature, NewIdxState)} of
+        {Sig, Sig} -> ok;
+        _ -> erlang:error(signature_mismatch)
+    end.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/c296d042/src/couch_index_api.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_api.erl b/src/couch_index_api.erl
new file mode 100644
index 0000000..9d3a67c
--- /dev/null
+++ b/src/couch_index_api.erl
@@ -0,0 +1,54 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_index_api).
+
+get(Field, State) ->
+    ok.
+
+init(Db, Ddoc) ->
+    ok.
+
+open(Db, State) ->
+    ok.
+
+close(State) ->
+    ok.
+
+delete(State) ->
+    ok.
+
+reset(State) ->
+    ok.
+
+
+start_update(State, PurgedState, NumChanges) ->
+    {ok, State}.
+
+purge(Db, PurgeSeq, PurgedIdRevs, State) ->
+    ok.
+
+process_doc(Doc, Seq, State) ->
+    ok.
+
+finish_update(State) ->
+    {ok, State}.
+
+commit(State) ->
+    ok.
+
+
+compact(Parent, State, Opts) ->
+    ok.
+
+swap_compacted(OldState, NewState) ->
+    ok.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/c296d042/src/couch_index_compactor.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_compactor.erl b/src/couch_index_compactor.erl
new file mode 100644
index 0000000..6e9fb2e
--- /dev/null
+++ b/src/couch_index_compactor.erl
@@ -0,0 +1,113 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_index_compactor).
+-behaviour(gen_server).
+
+
+%% API
+-export([start_link/2, run/2, cancel/1, is_running/1]).
+
+%% gen_server callbacks
+-export([init/1, terminate/2, code_change/3]).
+-export([handle_call/3, handle_cast/2, handle_info/2]).
+
+
+-include_lib("couch/include/couch_db.hrl").
+
+-record(st, {
+    idx,
+    mod,
+    pid
+}).
+
+
+start_link(Index, Module) ->
+    gen_server:start_link(?MODULE, {Index, Module}, []).
+
+
+run(Pid, IdxState) ->
+    gen_server:call(Pid, {compact, IdxState}).
+
+
+cancel(Pid) ->
+    gen_server:call(Pid, cancel).
+
+
+is_running(Pid) ->
+    gen_server:call(Pid, is_running).
+
+
+init({Index, Module}) ->
+    process_flag(trap_exit, true),
+    {ok, #st{idx=Index, mod=Module}}.
+
+
+terminate(_Reason, State) ->
+    couch_util:shutdown_sync(State#st.pid),
+    ok.
+
+
+handle_call({compact, _}, _From, #st{pid=Pid}=State) when is_pid(Pid) ->
+    {reply, {ok, Pid}, State};
+handle_call({compact, IdxState}, _From, #st{idx=Idx}=State) ->
+    Pid = spawn_link(fun() -> compact(Idx, State#st.mod, IdxState) end),
+    {reply, {ok, Pid}, State#st{pid=Pid}};
+handle_call(cancel, _From, #st{pid=undefined}=State) ->
+    {reply, ok, State};
+handle_call(cancel, _From, #st{pid=Pid}=State) ->
+    unlink(Pid),
+    exit(Pid, kill),
+    {reply, ok, State#st{pid=undefined}};
+handle_call(is_running, _From, #st{pid=Pid}=State) when is_pid(Pid) ->
+    {reply, true, State};
+handle_call(is_running, _From, State) ->
+    {reply, false, State}.
+
+
+handle_cast(_Mesg, State) ->
+    {stop, unknown_cast, State}.
+
+
+handle_info({'EXIT', Pid, normal}, #st{pid=Pid}=State) ->
+    {noreply, State#st{pid=undefined}};
+handle_info({'EXIT', _Pid, normal}, State) ->
+    {noreply, State};
+handle_info({'EXIT', Pid, _Reason}, #st{idx=Pid}=State) ->
+    {stop, normal, State};
+handle_info(_Mesg, State) ->
+    {stop, unknown_info, State}.
+
+
+code_change(_OldVsn, State, _Extra) ->
+    {ok, State}.
+
+
+compact(Parent, Mod, IdxState) ->
+    compact(Parent, Mod, IdxState, []).
+
+compact(Idx, Mod, IdxState, Opts) ->
+    DbName = Mod:get(db_name, IdxState),
+    Args = [DbName, Mod:get(idx_name, IdxState)],
+    ?LOG_INFO("Compaction started for db: ~s idx: ~s", Args),
+    {ok, NewIdxState} = couch_util:with_db(DbName, fun(Db) ->
+        Mod:compact(Db, IdxState, Opts)
+    end),
+    ok = Mod:commit(NewIdxState),
+    case gen_server:call(Idx, {compacted, NewIdxState}) of
+        recompact ->
+            ?LOG_INFO("Compaction restarting for db: ~s idx: ~s", Args),
+            compact(Idx, Mod, NewIdxState, [recompact]);
+        _ ->
+            ?LOG_INFO("Compaction finished for db: ~s idx: ~s", Args),
+            ok
+    end.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/c296d042/src/couch_index_server.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_server.erl b/src/couch_index_server.erl
new file mode 100644
index 0000000..86791db
--- /dev/null
+++ b/src/couch_index_server.erl
@@ -0,0 +1,203 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_index_server).
+-behaviour(gen_server).
+
+-export([start_link/0, get_index/4, get_index/3, get_index/2]).
+-export([config_change/2, update_notify/1]).
+
+-export([init/1, terminate/2, code_change/3]).
+-export([handle_call/3, handle_cast/2, handle_info/2]).
+
+-include_lib("couch/include/couch_db.hrl").
+
+-define(BY_SIG, couchdb_indexes_by_sig).
+-define(BY_PID, couchdb_indexes_by_pid).
+-define(BY_DB, couchdb_indexes_by_db).
+
+
+-record(st, {root_dir,
+             notifier_pid}).
+
+start_link() ->
+    gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
+
+
+get_index(Module, DbName, DDoc) ->
+    get_index(Module, DbName, DDoc, nil).
+
+
+get_index(Module, DbName, DDoc, Fun) when is_binary(DbName) ->
+    couch_util:with_db(DbName, fun(Db) ->
+        get_index(Module, Db, DDoc, Fun)
+    end);
+get_index(Module, Db, DDoc, Fun) when is_binary(DDoc) ->
+    case couch_db:open_doc(Db, DDoc, [ejson_body]) of
+        {ok, Doc} -> get_index(Module, Db, Doc, Fun);
+        Error -> Error
+    end;
+get_index(Module, Db, DDoc, Fun) when is_function(Fun, 1) ->
+    {ok, InitState} = Module:init(Db, DDoc),
+    {ok, FunResp} = Fun(InitState),
+    {ok, Pid} = get_index(Module, InitState),
+    {ok, Pid, FunResp};
+get_index(Module, Db, DDoc, _Fun) ->
+    {ok, InitState} = Module:init(Db, DDoc),
+    get_index(Module, InitState).
+
+
+get_index(Module, IdxState) ->
+    DbName = Module:get(db_name, IdxState),
+    Sig = Module:get(signature, IdxState),
+    case ets:lookup(?BY_SIG, {DbName, Sig}) of
+        [{_, Pid}] when is_pid(Pid) ->
+            {ok, Pid};
+        _ ->
+            Args = {Module, IdxState, DbName, Sig},
+            gen_server:call(?MODULE, {get_index, Args}, infinity)
+    end.
+
+
+init([]) ->
+    process_flag(trap_exit, true),
+    couch_config:register(fun ?MODULE:config_change/2),
+    ets:new(?BY_SIG, [protected, set, named_table]),
+    ets:new(?BY_PID, [private, set, named_table]),
+    ets:new(?BY_DB, [protected, bag, named_table]),
+
+    {ok, NotifierPid} = couch_db_update_notifier:start_link(
+            fun ?MODULE:update_notify/1),
+    RootDir = couch_index_util:root_dir(),
+    couch_file:init_delete_dir(RootDir),
+    {ok, #st{root_dir=RootDir,
+             notifier_pid=NotifierPid}}.
+
+
+terminate(_Reason, _State) ->
+    Pids = [Pid || {Pid, _} <- ets:tab2list(?BY_PID)],
+    lists:map(fun couch_util:shutdown_sync/1, Pids),
+    ok.
+
+
+handle_call({get_index, {_Mod, _IdxState, DbName, Sig}=Args}, From, State) ->
+    case ets:lookup(?BY_SIG, {DbName, Sig}) of
+        [] ->
+            spawn_link(fun() -> new_index(Args) end),
+            ets:insert(?BY_SIG, {{DbName, Sig}, [From]}),
+            {noreply, State};
+        [{_, Waiters}] when is_list(Waiters) ->
+            ets:insert(?BY_SIG, {{DbName, Sig}, [From | Waiters]}),
+            {noreply, State};
+        [{_, Pid}] when is_pid(Pid) ->
+            {reply, {ok, Pid}, State}
+    end;
+handle_call({async_open, {DbName, DDocId, Sig}, {ok, Pid}}, _From, State) ->
+    [{_, Waiters}] = ets:lookup(?BY_SIG, {DbName, Sig}),
+    [gen_server:reply(From, {ok, Pid}) || From <- Waiters],
+    link(Pid),
+    add_to_ets(DbName, Sig, DDocId, Pid),
+    {reply, ok, State};
+handle_call({async_error, {DbName, _DDocId, Sig}, Error}, _From, State) ->
+    [{_, Waiters}] = ets:lookup(?BY_SIG, {DbName, Sig}),
+    [gen_server:reply(From, Error) || From <- Waiters],
+    ets:delete(?BY_SIG, {DbName, Sig}),
+    {reply, ok, State};
+handle_call({reset_indexes, DbName}, _From, State) ->
+    reset_indexes(DbName, State#st.root_dir),
+    {reply, ok, State}.
+
+
+handle_cast({reset_indexes, DbName}, State) ->
+    reset_indexes(DbName, State#st.root_dir),
+    {noreply, State}.
+
+handle_info({'EXIT', Pid, Reason}, Server) ->
+    case ets:lookup(?BY_PID, Pid) of
+        [{Pid, {DbName, Sig}}] ->
+            [{DbName, {DDocId, Sig}}] =
+                ets:match_object(?BY_DB, {DbName, {'$1', Sig}}),
+            rem_from_ets(DbName, Sig, DDocId, Pid);
+        [] when Reason /= normal ->
+            exit(Reason);
+        _Else ->
+            ok
+    end,
+    {noreply, Server}.
+
+
+code_change(_OldVsn, State, _Extra) ->
+    {ok, State}.
+
+
+new_index({Mod, IdxState, DbName, Sig}) ->
+    DDocId = Mod:get(idx_name, IdxState),
+    case couch_index:start_link({Mod, IdxState}) of
+        {ok, Pid} ->
+            ok = gen_server:call(
+                ?MODULE, {async_open, {DbName, DDocId, Sig}, {ok, Pid}}),
+            unlink(Pid);
+        Error ->
+            ok = gen_server:call(
+                ?MODULE, {async_error, {DbName, DDocId, Sig}, Error})
+    end.
+
+
+reset_indexes(DbName, Root) ->
+    % shutdown all the updaters and clear the files, the db got changed
+    Fun = fun({_, {DDocId, Sig}}) ->
+        [{_, Pid}] = ets:lookup(?BY_SIG, {DbName, Sig}),
+        MRef = erlang:monitor(process, Pid),
+        gen_server:cast(Pid, delete),
+        receive {'DOWN', MRef, _, _, _} -> ok end,
+        rem_from_ets(DbName, Sig, DDocId, Pid)
+    end,
+    lists:foreach(Fun, ets:lookup(?BY_DB, DbName)),
+    Path = couch_index_util:index_dir("", DbName),
+    couch_file:nuke_dir(Root, Path).
+
+
+add_to_ets(DbName, Sig, DDocId, Pid) ->
+    ets:insert(?BY_SIG, {{DbName, Sig}, Pid}),
+    ets:insert(?BY_PID, {Pid, {DbName, Sig}}),
+    ets:insert(?BY_DB, {DbName, {DDocId, Sig}}).
+
+
+rem_from_ets(DbName, Sig, DDocId, Pid) ->
+    ets:delete(?BY_SIG, {DbName, Sig}),
+    ets:delete(?BY_PID, Pid),
+    ets:delete_object(?BY_DB, {DbName, {DDocId, Sig}}).
+
+
+config_change("couchdb", "view_index_dir") ->
+    exit(whereis(?MODULE), config_change);
+config_change("couchdb", "index_dir") ->
+    exit(whereis(?MODULE), config_change).
+
+
+update_notify({deleted, DbName}) ->
+    gen_server:cast(?MODULE, {reset_indexes, DbName});
+update_notify({created, DbName}) ->
+    gen_server:cast(?MODULE, {reset_indexes, DbName});
+update_notify({ddoc_updated, {DbName, DDocId}}) ->
+    lists:foreach(
+        fun({_DbName, {_DDocId, Sig}}) ->
+            case ets:lookup(?BY_SIG, {DbName, Sig}) of
+                [{_, IndexPid}] ->
+                    (catch gen_server:cast(IndexPid, ddoc_updated));
+                [] ->
+                    ok
+            end
+        end,
+        ets:match_object(?BY_DB, {DbName, {DDocId, '$1'}}));
+update_notify(_) ->
+    ok.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/c296d042/src/couch_index_sup.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_sup.erl b/src/couch_index_sup.erl
new file mode 100644
index 0000000..fd97814
--- /dev/null
+++ b/src/couch_index_sup.erl
@@ -0,0 +1,29 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_index_sup).
+-behaviour(supervisor).
+
+-export([start_link/0]).
+-export([init/1]).
+
+
+%% Helper macro for declaring children of supervisor
+-define(CHILD(I), {I, {I, start_link, []}, permanent, 5000, worker, [I]}).
+
+start_link() ->
+    supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+
+init([]) ->
+    Server = ?CHILD(couch_index_server),
+    {ok, {{one_for_one, 10, 3600}, [Server]}}.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/c296d042/src/couch_index_updater.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_updater.erl b/src/couch_index_updater.erl
new file mode 100644
index 0000000..9f54a56
--- /dev/null
+++ b/src/couch_index_updater.erl
@@ -0,0 +1,200 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_index_updater).
+-behaviour(gen_server).
+
+
+%% API
+-export([start_link/2, run/2, is_running/1, update/2, restart/2]).
+
+%% gen_server callbacks
+-export([init/1, terminate/2, code_change/3]).
+-export([handle_call/3, handle_cast/2, handle_info/2]).
+
+-include_lib("couch/include/couch_db.hrl").
+
+-record(st, {
+    idx,
+    mod,
+    pid=nil
+}).
+
+
+start_link(Index, Module) ->
+    gen_server:start_link(?MODULE, {Index, Module}, []).
+
+
+run(Pid, IdxState) ->
+    gen_server:call(Pid, {update, IdxState}).
+
+
+is_running(Pid) ->
+    gen_server:call(Pid, is_running).
+
+
+update(Mod, State) ->
+    update(nil, Mod, State).
+
+
+restart(Pid, IdxState) ->
+    gen_server:call(Pid, {restart, IdxState}).
+
+
+init({Index, Module}) ->
+    process_flag(trap_exit, true),
+    {ok, #st{idx=Index, mod=Module}}.
+
+
+terminate(_Reason, State) ->
+    couch_util:shutdown_sync(State#st.pid),
+    ok.
+
+
+handle_call({update, _IdxState}, _From, #st{pid=Pid}=State) when is_pid(Pid) ->
+    {reply, ok, State};
+handle_call({update, IdxState}, _From, #st{idx=Idx, mod=Mod}=State) ->
+    Args = [Mod:get(db_name, IdxState), Mod:get(idx_name, IdxState)],
+    ?LOG_INFO("Starting index update for db: ~s idx: ~s", Args),
+    Pid = spawn_link(fun() -> update(Idx, Mod, IdxState) end),
+    {reply, ok, State#st{pid=Pid}};
+handle_call({restart, IdxState}, _From, #st{idx=Idx, mod=Mod}=State) ->
+    Args = [Mod:get(db_name, IdxState), Mod:get(idx_name, IdxState)],
+    ?LOG_INFO("Restarting index update for db: ~s idx: ~s", Args),
+    case is_pid(State#st.pid) of
+        true -> couch_util:shutdown_sync(State#st.pid);
+        _ -> ok
+    end,
+    Pid = spawn_link(fun() -> update(Idx, State#st.mod, IdxState) end),
+    {reply, ok, State#st{pid=Pid}};
+handle_call(is_running, _From, #st{pid=Pid}=State) when is_pid(Pid) ->
+    {reply, true, State};
+handle_call(is_running, _From, State) ->
+    {reply, false, State}.
+
+
+handle_cast(_Mesg, State) ->
+    {stop, unknown_cast, State}.
+
+
+handle_info({'EXIT', _, {updated, Pid, IdxState}}, #st{pid=Pid}=State) ->
+    Mod = State#st.mod,
+    Args = [Mod:get(db_name, IdxState), Mod:get(idx_name, IdxState)],
+    ?LOG_INFO("Index update finished for db: ~s idx: ~s", Args),
+    ok = gen_server:cast(State#st.idx, {updated, IdxState}),
+    {noreply, State#st{pid=undefined}};
+handle_info({'EXIT', _, {reset, Pid}}, #st{idx=Idx, pid=Pid}=State) ->
+    {ok, NewIdxState} = gen_server:call(State#st.idx, reset),
+    Pid2 = spawn_link(fun() -> update(Idx, State#st.mod, NewIdxState) end),
+    {noreply, State#st{pid=Pid2}};
+handle_info({'EXIT', Pid, normal}, #st{pid=Pid}=State) ->
+    {noreply, State#st{pid=undefined}};
+handle_info({'EXIT', Pid, {{nocatch, Error}, _Trace}}, State) ->
+    handle_info({'EXIT', Pid, Error}, State);
+handle_info({'EXIT', Pid, Error}, #st{pid=Pid}=State) ->
+    ok = gen_server:cast(State#st.idx, {update_error, Error}),
+    {noreply, State#st{pid=undefined}};
+handle_info({'EXIT', Pid, _Reason}, #st{idx=Pid}=State) ->
+    {stop, normal, State};
+handle_info({'EXIT', _Pid, normal}, State) ->
+    {noreply, State};
+handle_info(_Mesg, State) ->
+    {stop, unknown_info, State}.
+
+
+code_change(_OldVsn, State, _Extra) ->
+    {ok, State}.
+
+
+update(Idx, Mod, IdxState) ->
+    DbName = Mod:get(db_name, IdxState),
+    CurrSeq = Mod:get(update_seq, IdxState),
+    UpdateOpts = Mod:get(update_options, IdxState),
+    CommittedOnly = lists:member(committed_only, UpdateOpts),
+    IncludeDesign = lists:member(include_design, UpdateOpts),
+    DocOpts = case lists:member(local_seq, UpdateOpts) of
+        true -> [conflicts, deleted_conflicts, local_seq];
+        _ -> [conflicts, deleted_conflicts]
+    end,
+
+    couch_util:with_db(DbName, fun(Db) ->
+        DbUpdateSeq = couch_db:get_update_seq(Db),
+        DbCommittedSeq = couch_db:get_committed_update_seq(Db),
+
+        PurgedIdxState = case purge_index(Db, Mod, IdxState) of
+            {ok, IdxState0} -> IdxState0;
+            reset -> exit({reset, self()})
+        end,
+
+        NumChanges = couch_db:count_changes_since(Db, CurrSeq),
+
+        LoadDoc = fun(DocInfo) ->
+            #doc_info{
+                id=DocId,
+                high_seq=Seq,
+                revs=[#rev_info{deleted=Deleted} | _]
+            } = DocInfo,
+
+            case {IncludeDesign, DocId} of
+                {false, <<"_design/", _/binary>>} ->
+                    {nil, Seq};
+                _ when Deleted ->
+                    {#doc{id=DocId, deleted=true}, Seq};
+                _ ->
+                    {ok, Doc} = couch_db:open_doc_int(Db, DocInfo, DocOpts),
+                    {Doc, Seq}
+            end
+        end,
+
+        Proc = fun(DocInfo, _, {IdxStateAcc, _}) ->
+            HighSeq = DocInfo#doc_info.high_seq,
+            case CommittedOnly and (HighSeq > DbCommittedSeq) of
+                true ->
+                    {stop, {IdxStateAcc, false}};
+                false ->
+                    {Doc, Seq} = LoadDoc(DocInfo),
+                    {ok, NewSt} = Mod:process_doc(Doc, Seq, IdxStateAcc),
+                    {ok, {NewSt, true}}
+            end
+        end,
+
+        {ok, InitIdxState} = Mod:start_update(Idx, PurgedIdxState, NumChanges),
+        Acc0 = {InitIdxState, true},
+        {ok, _, Acc} = couch_db:enum_docs_since(Db, CurrSeq, Proc, Acc0, []),
+        {ProcIdxSt, SendLast} = Acc,
+
+        % If we didn't bail due to hitting the last committed seq we need
+        % to send our last update_seq through.
+        {ok, LastIdxSt} = case SendLast of
+            true ->
+                Mod:process_doc(nil, DbUpdateSeq, ProcIdxSt);
+            _ ->
+                {ok, ProcIdxSt}
+        end,
+
+        {ok, FinalIdxState} = Mod:finish_update(LastIdxSt),
+        exit({updated, self(), FinalIdxState})
+    end).
+
+
+purge_index(Db, Mod, IdxState) ->
+    DbPurgeSeq = couch_db:get_purge_seq(Db),
+    IdxPurgeSeq = Mod:get(purge_seq, IdxState),
+    if
+        DbPurgeSeq == IdxPurgeSeq ->
+            {ok, IdxState};
+        DbPurgeSeq == IdxPurgeSeq + 1 ->
+            {ok, PurgedIdRevs} = couch_db:get_last_purged(Db),
+            Mod:purge(Db, DbPurgeSeq, PurgedIdRevs, IdxState);
+        true ->
+            reset
+    end.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/c296d042/src/couch_index_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_util.erl b/src/couch_index_util.erl
new file mode 100644
index 0000000..c833920
--- /dev/null
+++ b/src/couch_index_util.erl
@@ -0,0 +1,77 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_index_util).
+
+-export([root_dir/0, index_dir/2, index_file/3]).
+-export([load_doc/3, sort_lib/1, hexsig/1]).
+
+-include_lib("couch/include/couch_db.hrl").
+
+root_dir() ->
+  couch_config:get("couchdb", "view_index_dir").
+
+
+index_dir(Module, DbName) when is_binary(DbName) ->
+    DbDir = "." ++ binary_to_list(DbName) ++ "_design",
+    filename:join([root_dir(), DbDir, Module]);
+index_dir(Module, #db{}=Db) ->
+    index_dir(Module, couch_db:name(Db)).
+
+
+index_file(Module, DbName, FileName) ->
+    filename:join(index_dir(Module, DbName), FileName).
+
+
+load_doc(Db, #doc_info{}=DI, Opts) ->
+    Deleted = lists:member(deleted, Opts),
+    case (catch couch_db:open_doc(Db, DI, Opts)) of
+        {ok, #doc{deleted=false}=Doc} -> Doc;
+        {ok, #doc{deleted=true}=Doc} when Deleted -> Doc;
+        _Else -> null
+    end;
+load_doc(Db, {DocId, Rev}, Opts) ->
+    case (catch load_doc(Db, DocId, Rev, Opts)) of
+        #doc{deleted=false} = Doc -> Doc;
+        _ -> null
+    end.
+
+
+load_doc(Db, DocId, Rev, Options) ->
+    case Rev of
+        nil -> % open most recent rev
+            case (catch couch_db:open_doc(Db, DocId, Options)) of
+                {ok, Doc} -> Doc;
+                _Error -> null
+            end;
+        _ -> % open a specific rev (deletions come back as stubs)
+            case (catch couch_db:open_doc_revs(Db, DocId, [Rev], Options)) of
+                {ok, [{ok, Doc}]} -> Doc;
+                {ok, [{{not_found, missing}, Rev}]} -> null;
+                {ok, [_Else]} -> null
+            end
+    end.
+
+
+sort_lib({Lib}) ->
+    sort_lib(Lib, []).
+sort_lib([], LAcc) ->
+    lists:keysort(1, LAcc);
+sort_lib([{LName, {LObj}}|Rest], LAcc) ->
+    LSorted = sort_lib(LObj, []), % descend into nested object
+    sort_lib(Rest, [{LName, LSorted}|LAcc]);
+sort_lib([{LName, LCode}|Rest], LAcc) ->
+    sort_lib(Rest, [{LName, LCode}|LAcc]).
+
+
+hexsig(Sig) ->
+    couch_util:to_hex(binary_to_list(Sig)).


[04/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
Add a configurable whitelist of public user props

By default no user properties are public and attempts to view a users
document other than your own will return a 404. If the public_fields
setting of the users_db config section is set to a list of field
names, however, you will see that subset of fields for any user.

Also, if `public_fields` is set and non-empty,
`_users/_all_docs?include_docs=true` will return documents with stripped
field.

Contributed with code parts from @indutny


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/36514971
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/36514971
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/36514971

Branch: refs/heads/import-rcouch
Commit: 365149713bf99a3d3f0f0e7e8037bf9994e51268
Parents: d0262ce
Author: Robert Newson <rn...@apache.org>
Authored: Fri Jun 21 11:01:13 2013 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Fri Jun 21 22:49:46 2013 +0100

----------------------------------------------------------------------
 src/couch_mrview_http.erl | 43 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 40 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/36514971/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index 91587f1..61db4c0 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -106,8 +106,22 @@ all_docs_req(Req, Db, Keys) ->
         ok ->
             do_all_docs_req(Req, Db, Keys);
         _ ->
-            throw({forbidden, <<"Only admins can access _all_docs",
-                " of system databases.">>})
+            DbName = ?b2l(Db#db.name),
+            case couch_config:get("couch_httpd_auth",
+                                  "authentication_db",
+                                  "_users") of
+            DbName ->
+                case couch_config:get("couch_httpd_auth", "public_fields") of
+                undefined ->
+                    throw({forbidden, <<"Only admins can access _all_docs",
+                                        " of system databases.">>});
+                _ ->
+                    do_all_docs_req(Req, Db, Keys)
+                end;
+            _ ->
+                throw({forbidden, <<"Only admins can access _all_docs",
+                                    " of system databases.">>})
+            end
         end;
     false ->
         do_all_docs_req(Req, Db, Keys)
@@ -126,7 +140,16 @@ do_all_docs_req(Req, Db, Keys) ->
     Args = Args0#mrargs{preflight_fun=ETagFun},
     {ok, Resp} = couch_httpd:etag_maybe(Req, fun() ->
         VAcc0 = #vacc{db=Db, req=Req},
-        couch_mrview:query_all_docs(Db, Args, fun view_cb/2, VAcc0)
+        DbName = ?b2l(Db#db.name),
+        Callback = case couch_config:get("couch_httpd_auth",
+                                         "authentication_db",
+                                         "_users") of
+        DbName ->
+            fun filtered_view_cb/2;
+        _ ->
+            fun view_cb/2
+        end,
+        couch_mrview:query_all_docs(Db, Args, Callback, VAcc0)
     end),
     case is_record(Resp, vacc) of
         true -> {ok, Resp#vacc.resp};
@@ -154,6 +177,20 @@ design_doc_view(Req, Db, DDoc, ViewName, Keys) ->
     end.
 
 
+filtered_view_cb({row, Row0}, Acc) ->
+  Row1 = lists:map(fun({doc, null}) ->
+        {doc, null};
+    ({doc, Body}) ->
+        Doc = couch_users_db:strip_non_public_fields(#doc{body=Body}),
+        {doc, Doc#doc.body};
+    (KV) ->
+        KV
+    end, Row0),
+    view_cb({row, Row1}, Acc);
+filtered_view_cb(Obj, Acc) ->
+    view_cb(Obj, Acc).
+
+
 view_cb({meta, Meta}, #vacc{resp=undefined}=Acc) ->
     Headers = [{"ETag", Acc#vacc.etag}],
     {ok, Resp} = couch_httpd:start_json_response(Acc#vacc.req, 200, Headers),


[22/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
working release


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/cb131422
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/cb131422
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/cb131422

Branch: refs/heads/import-rcouch
Commit: cb131422fc43469d323df9ac05bd1d94c45aa1aa
Parents: 55874fb
Author: benoitc <be...@apache.org>
Authored: Tue Jan 7 16:14:56 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Thu Feb 6 10:51:40 2014 -0600

----------------------------------------------------------------------
 src/couch_mrview.app.src | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/cb131422/src/couch_mrview.app.src
----------------------------------------------------------------------
diff --git a/src/couch_mrview.app.src b/src/couch_mrview.app.src
index 52898a6..cce2c97 100644
--- a/src/couch_mrview.app.src
+++ b/src/couch_mrview.app.src
@@ -12,7 +12,7 @@
 
 {application, couch_mrview, [
     {description, "CouchDB Map/Reduce Views"},
-    {vsn, "%version%"},
+    {vsn, "1.3.0"},
     {modules, [
         couch_mrview,
         couch_mrview_compactor,


[03/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
Unfix view compaction progress reports

This reverts the compaction task status progress back to what exists on
1.2.x. The issue is that we use the number of documents in the database
instead of the number of docids in the union of all views (the number of
rows in the view's id btree). In this particular case the desire to have
seamless view upgrades outweighs fixing the relatively minor UI bug.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/d0262cef
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/d0262cef
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/d0262cef

Branch: refs/heads/import-rcouch
Commit: d0262cefb653290fb30a3868e1b9a7c53c31a300
Parents: 0e28dfc
Author: Paul J. Davis <pa...@gmail.com>
Authored: Thu Feb 7 13:28:56 2013 -0600
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Thu Feb 7 13:28:56 2013 -0600

----------------------------------------------------------------------
 src/couch_mrview_compactor.erl | 12 ++++++++----
 src/couch_mrview_util.erl      |  7 +------
 2 files changed, 9 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d0262cef/src/couch_mrview_compactor.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_compactor.erl b/src/couch_mrview_compactor.erl
index b500ce3..fe718ca 100644
--- a/src/couch_mrview_compactor.erl
+++ b/src/couch_mrview_compactor.erl
@@ -43,10 +43,15 @@ compact(State) ->
         views=Views
     } = State,
 
-    EmptyState = couch_util:with_db(DbName, fun(Db) ->
+    {EmptyState, NumDocIds} = couch_util:with_db(DbName, fun(Db) ->
         CompactFName = couch_mrview_util:compaction_file(DbName, Sig),
         {ok, Fd} = couch_mrview_util:open_file(CompactFName),
-        couch_mrview_util:reset_index(Db, Fd, State)
+        ESt = couch_mrview_util:reset_index(Db, Fd, State),
+
+        {ok, DbReduce} = couch_btree:full_reduce(Db#db.fulldocinfo_by_id_btree),
+        Count = element(1, DbReduce),
+
+        {ESt, Count}
     end),
 
     #mrst{
@@ -54,13 +59,12 @@ compact(State) ->
         views = EmptyViews
     } = EmptyState,
 
-    {ok, Count} = couch_btree:full_reduce(IdBtree),
     TotalChanges = lists:foldl(
         fun(View, Acc) ->
             {ok, Kvs} = couch_mrview_util:get_row_count(View),
             Acc + Kvs
         end,
-        Count, Views),
+        NumDocIds, Views),
     couch_task_status:add_task([
         {type, view_compaction},
         {database, DbName},

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d0262cef/src/couch_mrview_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_util.erl b/src/couch_mrview_util.erl
index 092ae3d..18185af 100644
--- a/src/couch_mrview_util.erl
+++ b/src/couch_mrview_util.erl
@@ -197,12 +197,7 @@ init_state(Db, Fd, State, Header) ->
     end,
     ViewStates2 = lists:map(StateUpdate, ViewStates),
 
-    IdReduce = fun
-        (reduce, KVs) -> length(KVs);
-        (rereduce, Reds) -> lists:sum(Reds)
-    end,
-
-    IdBtOpts = [{reduce, IdReduce}, {compression, couch_db:compression(Db)}],
+    IdBtOpts = [{compression, couch_db:compression(Db)}],
     {ok, IdBtree} = couch_btree:open(IdBtreeState, Fd, IdBtOpts),
 
     OpenViewFun = fun(St, View) -> open_view(Db, Fd, Lang, St, View) end,


[12/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
Extend support for attachment-related query params

Until now, the boolean query parameters `attachments` and
`att_encoding_info` have only been supported for the document API
endpoint (`/{db}/{docid}`).

This extends support for queries to the changes (`/{db}/_changes`) and
view (`/{db}/_design/{ddoc}/_view/{view}`) API endpoints:

* If `include_docs` and `attachments` equal `true`, the Base64-encoded
  contents of attachments are included with the documents in changes or
  view query results, respectively.

* If `include_docs` and `att_encoding_info` equal `true`, encoding
  information is included in attachment stubs if the particular
  attachment is compressed.

Closes COUCHDB-1923.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/e650b435
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/e650b435
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/e650b435

Branch: refs/heads/import-rcouch
Commit: e650b435835b1aad9b394c2de675ec571c97a4a4
Parents: f5c829f
Author: Klaus Trainer <kl...@posteo.de>
Authored: Fri Nov 15 17:02:20 2013 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Nov 28 22:59:13 2013 +0000

----------------------------------------------------------------------
 include/couch_mrview.hrl  |  1 +
 src/couch_mrview_http.erl | 16 ++++++++++++++++
 src/couch_mrview_util.erl | 22 +++++++++++-----------
 3 files changed, 28 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/e650b435/include/couch_mrview.hrl
----------------------------------------------------------------------
diff --git a/include/couch_mrview.hrl b/include/couch_mrview.hrl
index bf3bcac..e4ec66d 100644
--- a/include/couch_mrview.hrl
+++ b/include/couch_mrview.hrl
@@ -72,6 +72,7 @@
     stale = false,
     inclusive_end = true,
     include_docs = false,
+    doc_options = [],
     update_seq=false,
     conflicts,
     callback,

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/e650b435/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index 8b914ef..7b92034 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -348,6 +348,22 @@ parse_qs(Key, Val, Args) ->
             Args#mrargs{inclusive_end=parse_boolean(Val)};
         "include_docs" ->
             Args#mrargs{include_docs=parse_boolean(Val)};
+        "attachments" ->
+            case parse_boolean(Val) of
+            true ->
+                Opts = Args#mrargs.doc_options,
+                Args#mrargs{doc_options=[attachments|Opts]};
+            false ->
+                Args
+            end;
+        "att_encoding_info" ->
+            case parse_boolean(Val) of
+            true ->
+                Opts = Args#mrargs.doc_options,
+                Args#mrargs{doc_options=[att_encoding_info|Opts]};
+            false ->
+                Args
+            end;
         "update_seq" ->
             Args#mrargs{update_seq=parse_boolean(Val)};
         "conflicts" ->

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/e650b435/src/couch_mrview_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_util.erl b/src/couch_mrview_util.erl
index 18185af..a3b0581 100644
--- a/src/couch_mrview_util.erl
+++ b/src/couch_mrview_util.erl
@@ -668,24 +668,24 @@ expand_dups([KV | Rest], Acc) ->
 
 maybe_load_doc(_Db, _DI, #mrargs{include_docs=false}) ->
     [];
-maybe_load_doc(Db, #doc_info{}=DI, #mrargs{conflicts=true}) ->
-    doc_row(couch_index_util:load_doc(Db, DI, [conflicts]));
-maybe_load_doc(Db, #doc_info{}=DI, _Args) ->
-    doc_row(couch_index_util:load_doc(Db, DI, [])).
+maybe_load_doc(Db, #doc_info{}=DI, #mrargs{conflicts=true, doc_options=Opts}) ->
+    doc_row(couch_index_util:load_doc(Db, DI, [conflicts]), Opts);
+maybe_load_doc(Db, #doc_info{}=DI, #mrargs{doc_options=Opts}) ->
+    doc_row(couch_index_util:load_doc(Db, DI, []), Opts).
 
 
 maybe_load_doc(_Db, _Id, _Val, #mrargs{include_docs=false}) ->
     [];
-maybe_load_doc(Db, Id, Val, #mrargs{conflicts=true}) ->
-    doc_row(couch_index_util:load_doc(Db, docid_rev(Id, Val), [conflicts]));
-maybe_load_doc(Db, Id, Val, _Args) ->
-    doc_row(couch_index_util:load_doc(Db, docid_rev(Id, Val), [])).
+maybe_load_doc(Db, Id, Val, #mrargs{conflicts=true, doc_options=Opts}) ->
+    doc_row(couch_index_util:load_doc(Db, docid_rev(Id, Val), [conflicts]), Opts);
+maybe_load_doc(Db, Id, Val, #mrargs{doc_options=Opts}) ->
+    doc_row(couch_index_util:load_doc(Db, docid_rev(Id, Val), []), Opts).
 
 
-doc_row(null) ->
+doc_row(null, _Opts) ->
     [{doc, null}];
-doc_row(Doc) ->
-    [{doc, couch_doc:to_json_obj(Doc, [])}].
+doc_row(Doc, Opts) ->
+    [{doc, couch_doc:to_json_obj(Doc, Opts)}].
 
 
 docid_rev(Id, {Props}) ->


[19/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
extract couch_httpd changes API in its own module


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/72589456
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/72589456
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/72589456

Branch: refs/heads/import-rcouch
Commit: 725894562adc35e2c5e943085660bf85e0e6ccf6
Parents: b60ac21
Author: benoitc <bc...@gmail.com>
Authored: Sun Feb 2 19:54:01 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Thu Feb 6 10:51:40 2014 -0600

----------------------------------------------------------------------
 src/couch_index.erl | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/72589456/src/couch_index.erl
----------------------------------------------------------------------
diff --git a/src/couch_index.erl b/src/couch_index.erl
index c09a110..c48c066 100644
--- a/src/couch_index.erl
+++ b/src/couch_index.erl
@@ -219,9 +219,18 @@ handle_cast({new_state, NewIdxState}, State) ->
     } = State,
     assert_signature_match(Mod, OldIdxState, NewIdxState),
     CurrSeq = Mod:get(update_seq, NewIdxState),
+
+    DbName = Mod:get(db_name, NewIdxState),
+    DDocId = Mod:get(idx_name, NewIdxState),
+
+    %% notify to event listeners that the index has been
+    %% updated
+    couch_index_event:notify({index_update,
+                              {DbName, DDocId,
+                               Mod}}),
     Args = [
-        Mod:get(db_name, NewIdxState),
-        Mod:get(idx_name, NewIdxState),
+        DbName,
+        DDocId,
         CurrSeq
     ],
     ?LOG_DEBUG("Updated index for db: ~s idx: ~s seq: ~B", Args),
@@ -242,12 +251,27 @@ handle_cast(stop, State) ->
     {stop, normal, State};
 handle_cast(delete, State) ->
     #st{mod=Mod, idx_state=IdxState} = State,
+    DbName = Mod:get(db_name, IdxState),
+    DDocId = Mod:get(idx_name, IdxState),
+
     ok = Mod:delete(IdxState),
+
+    %% notify about the index deletion
+    couch_index_event:notify({index_delete,
+                              {DbName, DDocId, Mod}}),
+
     {stop, normal, State};
 handle_cast(ddoc_updated, State) ->
     #st{mod = Mod, idx_state = IdxState, waiters = Waiters} = State,
     DbName = Mod:get(db_name, IdxState),
     DDocId = Mod:get(idx_name, IdxState),
+
+    %% notify to event listeners that the index has been
+    %% updated
+    couch_index_event:notify({index_update,
+                              {DbName, DDocId,
+                               Mod}}),
+
     Shutdown = couch_util:with_db(DbName, fun(Db) ->
         case couch_db:open_doc(Db, DDocId, [ejson_body]) of
             {not_found, deleted} ->


[13/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
add `make test` target . all erlang test pass

note: from time to time there is a timing issue on 200- test that need
to be fixed. It is most probably due to the way the indexer is
supervised.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/2de6fb49
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/2de6fb49
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/2de6fb49

Branch: refs/heads/import-rcouch
Commit: 2de6fb493ea0c383f217b1d7ffa29e864a76e2fc
Parents: bfd7b43
Author: benoitc <be...@apache.org>
Authored: Thu Jan 9 16:24:32 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Thu Feb 6 10:51:40 2014 -0600

----------------------------------------------------------------------
 test/01-load.t         | 1 +
 test/02-map-views.t    | 2 ++
 test/03-red-views.t    | 3 +++
 test/04-index-info.t   | 2 ++
 test/05-collation.t    | 3 +++
 test/06-all-docs.t     | 2 ++
 test/07-compact-swap.t | 8 ++++++--
 7 files changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/2de6fb49/test/01-load.t
----------------------------------------------------------------------
diff --git a/test/01-load.t b/test/01-load.t
index a57c1a7..ae66525 100644
--- a/test/01-load.t
+++ b/test/01-load.t
@@ -1,5 +1,6 @@
 #!/usr/bin/env escript
 %% -*- erlang -*-
+%%! -pa ./src/deps/*/ebin -pa ./src/apps/*/ebin -pa ./src/test/etap
 
 % Licensed under the Apache License, Version 2.0 (the "License"); you may not
 % use this file except in compliance with the License. You may obtain a copy of

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/2de6fb49/test/02-map-views.t
----------------------------------------------------------------------
diff --git a/test/02-map-views.t b/test/02-map-views.t
index 7e1ca0c..ed1b1cc 100644
--- a/test/02-map-views.t
+++ b/test/02-map-views.t
@@ -1,5 +1,6 @@
 #!/usr/bin/env escript
 %% -*- erlang -*-
+%%! -pa ./src/deps/*/ebin -pa ./src/apps/*/ebin -pa ./src/test/etap
 
 % Licensed under the Apache License, Version 2.0 (the "License"); you may not
 % use this file except in compliance with the License. You may obtain a copy of
@@ -29,6 +30,7 @@ main(_) ->
 
 test() ->
     couch_server_sup:start_link(test_util:config_files()),
+    couch_index_sup:start_link(),
 
     {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, map),
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/2de6fb49/test/03-red-views.t
----------------------------------------------------------------------
diff --git a/test/03-red-views.t b/test/03-red-views.t
index 6ad341b..17b9148 100644
--- a/test/03-red-views.t
+++ b/test/03-red-views.t
@@ -1,5 +1,7 @@
 #!/usr/bin/env escript
 %% -*- erlang -*-
+%%! -pa ./src/deps/*/ebin -pa ./src/apps/*/ebin -pa ./src/test/etap
+
 
 % Licensed under the Apache License, Version 2.0 (the "License"); you may not
 % use this file except in compliance with the License. You may obtain a copy of
@@ -18,6 +20,7 @@ main(_) ->
 
 test() ->
     couch_server_sup:start_link(test_util:config_files()),
+    couch_index_sup:start_link(),
 
     {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, red),
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/2de6fb49/test/04-index-info.t
----------------------------------------------------------------------
diff --git a/test/04-index-info.t b/test/04-index-info.t
index 6b67b56..73c4dcc 100644
--- a/test/04-index-info.t
+++ b/test/04-index-info.t
@@ -1,5 +1,6 @@
 #!/usr/bin/env escript
 %% -*- erlang -*-
+%%! -pa ./src/deps/*/ebin -pa ./src/apps/*/ebin -pa ./src/test/etap
 
 % Licensed under the Apache License, Version 2.0 (the "License"); you may not
 % use this file except in compliance with the License. You may obtain a copy of
@@ -31,6 +32,7 @@ sig() -> <<"276df562b152b3c4e5d34024f62672ed">>.
 
 test() ->
     couch_server_sup:start_link(test_util:config_files()),
+    couch_index_sup:start_link(),
 
     {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, map),
     couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/2de6fb49/test/05-collation.t
----------------------------------------------------------------------
diff --git a/test/05-collation.t b/test/05-collation.t
index ac8f8bc..d476601 100644
--- a/test/05-collation.t
+++ b/test/05-collation.t
@@ -1,5 +1,6 @@
 #!/usr/bin/env escript
 %% -*- erlang -*-
+%%! -pa ./src/deps/*/ebin -pa ./src/apps/*/ebin -pa ./src/test/etap
 
 % Licensed under the Apache License, Version 2.0 (the "License"); you may not
 % use this file except in compliance with the License. You may obtain a copy of
@@ -19,6 +20,8 @@ main(_) ->
 
 test() ->
     couch_server_sup:start_link(test_util:config_files()),
+    couch_index_sup:start_link(),
+
     {ok, Db0} = couch_mrview_test_util:new_db(<<"foo">>, map),
     {ok, Db1} = couch_mrview_test_util:save_docs(Db0, docs()),
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/2de6fb49/test/06-all-docs.t
----------------------------------------------------------------------
diff --git a/test/06-all-docs.t b/test/06-all-docs.t
index 4501aa5..a19cd7e 100644
--- a/test/06-all-docs.t
+++ b/test/06-all-docs.t
@@ -1,5 +1,6 @@
 #!/usr/bin/env escript
 %% -*- erlang -*-
+%%! -pa ./src/deps/*/ebin -pa ./src/apps/*/ebin -pa ./src/test/etap
 
 % Licensed under the Apache License, Version 2.0 (the "License"); you may not
 % use this file except in compliance with the License. You may obtain a copy of
@@ -19,6 +20,7 @@ main(_) ->
 
 test() ->
     couch_server_sup:start_link(test_util:config_files()),
+    couch_index_sup:start_link(),
 
     {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, map),
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/2de6fb49/test/07-compact-swap.t
----------------------------------------------------------------------
diff --git a/test/07-compact-swap.t b/test/07-compact-swap.t
index 4bfe124..a74d273 100644
--- a/test/07-compact-swap.t
+++ b/test/07-compact-swap.t
@@ -1,5 +1,7 @@
 #!/usr/bin/env escript
 %% -*- erlang -*-
+%%! -pa ./src/deps/*/ebin -pa ./src/apps/*/ebin -pa ./src/test/etap
+
 
 % Licensed under the Apache License, Version 2.0 (the "License"); you may not
 % use this file except in compliance with the License. You may obtain a copy of
@@ -19,6 +21,8 @@ main(_) ->
 
 test() ->
     couch_server_sup:start_link(test_util:config_files()),
+    couch_index_sup:start_link(),
+
     {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, map, 1000),
     couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),
     test_swap(Db),
@@ -26,7 +30,7 @@ test() ->
 
 
 test_swap(Db) ->
-    {ok, QPid} = start_query(Db),    
+    {ok, QPid} = start_query(Db),
     {ok, MonRef} = couch_mrview:compact(Db, <<"_design/bar">>, [monitor]),
     receive
         {'DOWN', MonRef, process, _, _} -> ok
@@ -50,7 +54,7 @@ start_query(Db) ->
             ({row, _}, Count) -> {ok, Count+1};
             (_, Count) -> {ok, Count}
         end,
-        {ok, Result} = 
+        {ok, Result} =
         couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, [], CB, wait),
         Self ! {self(), Result}
     end),


[21/22] couch-mrview commit: updated refs/heads/import-rcouch to 7258945

Posted by da...@apache.org.
make couch_httpd a full couch application

With this change, the HTTP API is now handled by its own erlang
application and supervision. It also improved the way you can reload the
configuration and the modules. Now upgrading a listener or its
configuration is first removing it from the supervsion then start the
new process with the new configuration. This behaviour is similar to the
one you have in nginx.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/5813a97a
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/5813a97a
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/5813a97a

Branch: refs/heads/import-rcouch
Commit: 5813a97aafe9d1055934ad983bd064b81f714800
Parents: bce80b4
Author: benoitc <be...@apache.org>
Authored: Sat Jan 11 11:20:27 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Thu Feb 6 10:51:40 2014 -0600

----------------------------------------------------------------------
 test/02-map-views.t    | 1 +
 test/03-red-views.t    | 2 +-
 test/04-index-info.t   | 1 +
 test/05-collation.t    | 1 +
 test/06-all-docs.t     | 1 +
 test/07-compact-swap.t | 1 +
 6 files changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/5813a97a/test/02-map-views.t
----------------------------------------------------------------------
diff --git a/test/02-map-views.t b/test/02-map-views.t
index 567042d..98d6a8f 100644
--- a/test/02-map-views.t
+++ b/test/02-map-views.t
@@ -30,6 +30,7 @@ main(_) ->
 
 test() ->
     couch_server_sup:start_link(test_util:config_files()),
+    couch_httpd_sup:start_link(),
     {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, map),
 
     test_basic(Db),

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/5813a97a/test/03-red-views.t
----------------------------------------------------------------------
diff --git a/test/03-red-views.t b/test/03-red-views.t
index 7f52f75..e478521 100644
--- a/test/03-red-views.t
+++ b/test/03-red-views.t
@@ -20,7 +20,7 @@ main(_) ->
 
 test() ->
     couch_server_sup:start_link(test_util:config_files()),
-
+    couch_httpd_sup:start_link(),
     {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, red),
 
     test_basic(Db),

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/5813a97a/test/04-index-info.t
----------------------------------------------------------------------
diff --git a/test/04-index-info.t b/test/04-index-info.t
index 834b7d2..3f47436 100644
--- a/test/04-index-info.t
+++ b/test/04-index-info.t
@@ -32,6 +32,7 @@ sig() -> <<"276df562b152b3c4e5d34024f62672ed">>.
 
 test() ->
     couch_server_sup:start_link(test_util:config_files()),
+    couch_httpd_sup:start_link(),
 
     {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, map),
     couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/5813a97a/test/05-collation.t
----------------------------------------------------------------------
diff --git a/test/05-collation.t b/test/05-collation.t
index f98e88d..f0c4f0d 100644
--- a/test/05-collation.t
+++ b/test/05-collation.t
@@ -20,6 +20,7 @@ main(_) ->
 
 test() ->
     couch_server_sup:start_link(test_util:config_files()),
+    couch_httpd_sup:start_link(),
 
     {ok, Db0} = couch_mrview_test_util:new_db(<<"foo">>, map),
     {ok, Db1} = couch_mrview_test_util:save_docs(Db0, docs()),

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/5813a97a/test/06-all-docs.t
----------------------------------------------------------------------
diff --git a/test/06-all-docs.t b/test/06-all-docs.t
index 370825e..3a08b59 100644
--- a/test/06-all-docs.t
+++ b/test/06-all-docs.t
@@ -20,6 +20,7 @@ main(_) ->
 
 test() ->
     couch_server_sup:start_link(test_util:config_files()),
+    couch_httpd_sup:start_link(),
 
     {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, map),
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/5813a97a/test/07-compact-swap.t
----------------------------------------------------------------------
diff --git a/test/07-compact-swap.t b/test/07-compact-swap.t
index f7ebca2..9185a19 100644
--- a/test/07-compact-swap.t
+++ b/test/07-compact-swap.t
@@ -21,6 +21,7 @@ main(_) ->
 
 test() ->
     couch_server_sup:start_link(test_util:config_files()),
+    couch_httpd_sup:start_link(),
 
     {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, map, 1000),
     couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),