couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [30/35] git commit: Kill couch_db_event when it has installed handlers
Date Fri, 01 Aug 2014 09:10:26 GMT
Kill couch_db_event when it has installed handlers

This is to force the upgrade switch to the new couch_event application
force update notifications. Theoretically we could accomplish the same
thing with custom appups to forcefully remove couch_db_event from the
supervision tree but it turns out that's really hard.


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

Branch: refs/heads/windsor-merge
Commit: 022af54ff972e3ff7ce842f5c905dbfeb7d162f9
Parents: 0547000
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Sat Jun 15 11:45:59 2013 -0500
Committer: Robert Newson <rnewson@apache.org>
Committed: Wed Jul 30 17:48:55 2014 +0100

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


http://git-wip-us.apache.org/repos/asf/couchdb-couch-event/blob/022af54f/src/couch_event_server.erl
----------------------------------------------------------------------
diff --git a/src/couch_event_server.erl b/src/couch_event_server.erl
index 866bf7c..1bf8f1e 100644
--- a/src/couch_event_server.erl
+++ b/src/couch_event_server.erl
@@ -27,13 +27,18 @@
     code_change/3
 ]).
 
+-export([
+    watchdog/0
+]).
+
 
 -include("couch_event_int.hrl").
 
 
 -record(st, {
     by_pid,
-    by_dbname
+    by_dbname,
+    watchdog
 }).
 
 
@@ -46,7 +51,8 @@ init(_) ->
     {ok, ByDbName} = khash:new(),
     {ok, #st{
         by_pid = ByPid,
-        by_dbname = ByDbName
+        by_dbname = ByDbName,
+        watchdog = spawn_monitor(?MODULE, watchdog, [])
     }}.
 
 
@@ -90,6 +96,10 @@ handle_cast(Msg, St) ->
     {noreply, St}.
 
 
+handle_info({'DOWN', Ref, _, _, Reason}, #st{watchdog={_,Ref}}=St) ->
+    couch_log:notice("~s watchdog died: ~w", [?MODULE, Reason]),
+    erlang:send_after(60000, self(), spawn_watchdog),
+    {noreply, St#st{watchdog=undefined}};
 handle_info({'DOWN', Ref, process, Pid, _Reason}, St) ->
     case khash:get(St#st.by_pid, Pid) of
         {Ref, OldDbNames} ->
@@ -99,6 +109,10 @@ handle_info({'DOWN', Ref, process, Pid, _Reason}, St) ->
     end,
     {noreply, St};
 
+
+handle_info(spawn_watchdog, #st{watchdog=undefined}=St) ->
+    NewWD = spawn_monitor(?MODULE, watchdog, []),
+    {noreply, St#st{watchdog=NewWD}};
 handle_info(Msg, St) ->
     couch_log:notice("~s ignoring info ~w", [?MODULE, Msg]),
     {noreply, St}.
@@ -108,6 +122,18 @@ code_change(_OldVsn, St, _Extra) ->
     {ok, St}.
 
 
+watchdog() ->
+    Handlers = gen_event:which_handlers(couch_db_update),
+    case length(Handlers) > 0 of
+        true ->
+            exit(whereis(couch_db_update), force_upgrade);
+        false ->
+            ok
+    end,
+    timer:sleep(5000),
+    ?MODULE:watchdog().
+
+
 notify_listeners(ByDbName, DbName, Event) ->
     Msg = {'$couch_event', DbName, Event},
     notify_listeners(khash:get(ByDbName, all_dbs), Msg),


Mime
View raw message