You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by bb...@apache.org on 2014/10/31 20:53:37 UTC

[22/41] couch-mrview commit: updated refs/heads/master to 28e51f3

Make feed=continuous work for view changes


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/c8394f90
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/c8394f90
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/c8394f90

Branch: refs/heads/master
Commit: c8394f90dd93210ea5a4a7acfb3b580cc0414bbe
Parents: 062c1e7
Author: Benjamin Bastian <be...@gmail.com>
Authored: Fri Aug 22 17:46:13 2014 +0700
Committer: Benjamin Bastian <be...@gmail.com>
Committed: Thu Oct 30 13:38:34 2014 -0700

----------------------------------------------------------------------
 src/couch_mrview_http.erl            |  2 +-
 src/couch_mrview_index.erl           |  4 ++-
 src/couch_mrview_update_notifier.erl | 49 +++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/c8394f90/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index 1e54195..75c3cb5 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -64,7 +64,7 @@ handle_reindex_req(Req, _Db, _DDoc) ->
 
 handle_view_changes_req(#httpd{path_parts=[_,<<"_design">>,DDocName,<<"_view_changes">>,ViewName]}=Req, Db, _DDoc) ->
     ChangesArgs = couch_httpd_changes:parse_changes_query(Req, Db, true),
-    ChangesFun = couch_mrview_changes:handle_view_changes(ChangesArgs, Req, Db, DDocName, ViewName),
+    ChangesFun = couch_mrview_changes:handle_view_changes(ChangesArgs, Req, Db, <<"_design/", DDocName/binary>>, ViewName),
     couch_httpd_changes:handle_changes_req(Req, Db, ChangesArgs, ChangesFun).
 
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/c8394f90/src/couch_mrview_index.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_index.erl b/src/couch_mrview_index.erl
index 7598f13..0e6ef6f 100644
--- a/src/couch_mrview_index.erl
+++ b/src/couch_mrview_index.erl
@@ -178,7 +178,9 @@ finish_update(State) ->
 
 commit(State) ->
     Header = {State#mrst.sig, couch_mrview_util:make_header(State)},
-    couch_file:write_header(State#mrst.fd, Header).
+    Resp = couch_file:write_header(State#mrst.fd, Header),
+    couch_mrview_update_notifier:notify({index_update, State#mrst.db_name, State#mrst.idx_name}),
+    Resp.
 
 
 compact(Db, State, Opts) ->

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/c8394f90/src/couch_mrview_update_notifier.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_update_notifier.erl b/src/couch_mrview_update_notifier.erl
new file mode 100644
index 0000000..1837b1f
--- /dev/null
+++ b/src/couch_mrview_update_notifier.erl
@@ -0,0 +1,49 @@
+% 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_mrview_update_notifier).
+
+-behaviour(gen_event).
+
+-export([start_link/1, notify/1]).
+-export([init/1, terminate/2, handle_event/2, handle_call/2, handle_info/2, code_change/3, stop/1]).
+
+-include_lib("couch/include/couch_db.hrl").
+
+start_link(Exec) ->
+    couch_event_sup:start_link(couch_mrview_update, {couch_mrview_update_notifier, make_ref()}, Exec).
+
+notify(Event) ->
+    gen_event:notify(couch_mrview_update, Event).
+
+stop(Pid) ->
+    couch_event_sup:stop(Pid).
+
+init(Fun) ->
+    {ok, Fun}.
+
+terminate(_Reason, _State) ->
+    ok.
+
+handle_event(Event, Fun) ->
+    Fun(Event),
+    {ok, Fun}.
+
+handle_call(_Request, State) ->
+    {reply, ok, State}.
+
+handle_info({'EXIT', Pid, Reason}, Pid) ->
+    ?LOG_ERROR("View update notification process ~p died: ~p", [Pid, Reason]),
+    remove_handler.
+
+code_change(_OldVsn, State, _Extra) ->
+    {ok, State}.