couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chewbra...@apache.org
Subject [05/50] [abbrv] couch-replicator commit: updated refs/heads/1963-eunit-bigcouch to 3cf0b13
Date Thu, 28 Aug 2014 17:30:05 GMT
Update to use new couch_event application


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

Branch: refs/heads/1963-eunit-bigcouch
Commit: d6079a6f2420cb8d704f10e0d2b3953453d1fc83
Parents: dd96e21
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Tue Apr 23 17:57:15 2013 -0500
Committer: Robert Newson <rnewson@apache.org>
Committed: Tue Jul 29 13:44:46 2014 +0100

----------------------------------------------------------------------
 src/couch_replicator.app.src     |  3 +-
 src/couch_replicator_manager.erl | 67 +++++++++++++++++++++--------------
 src/couch_replicator_utils.erl   | 24 ++++++++-----
 3 files changed, 58 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/d6079a6f/src/couch_replicator.app.src
----------------------------------------------------------------------
diff --git a/src/couch_replicator.app.src b/src/couch_replicator.app.src
index 740d007..06c6c68 100644
--- a/src/couch_replicator.app.src
+++ b/src/couch_replicator.app.src
@@ -37,7 +37,8 @@
         stdlib,
         couch_log,
         mem3,
-        couch
+        couch,
+        couch_event
     ]}
 ]}.
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/d6079a6f/src/couch_replicator_manager.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator_manager.erl b/src/couch_replicator_manager.erl
index 71e6be0..949622a 100644
--- a/src/couch_replicator_manager.erl
+++ b/src/couch_replicator_manager.erl
@@ -26,6 +26,8 @@
 % config_listener callback
 -export([handle_config_change/5]).
 
+-export([handle_db_event/3]).
+
 -include_lib("couch/include/couch_db.hrl").
 -include_lib("mem3/include/mem3.hrl").
 -include("couch_replicator.hrl").
@@ -56,7 +58,7 @@
 ]).
 
 -record(state, {
-    db_notifier = nil,
+    event_listener = nil,
     scan_pid = nil,
     rep_start_pids = [],
     max_retries
@@ -134,7 +136,7 @@ init(_) ->
     ensure_rep_db_exists(LocalRepDb),
     Pid = changes_feed_loop(LocalRepDb, 0),
     {ok, #state{
-        db_notifier = db_update_notifier(),
+        event_listener = start_event_listener(),
         scan_pid = ScanPid,
         max_retries = retries_value(
             config:get("replicator", "max_replication_retry_count", "10")),
@@ -220,7 +222,7 @@ handle_info({'EXIT', From, Reason}, #state{scan_pid = From} = State) ->
     couch_log:error("Background scanner died. Reason: ~p", [Reason]),
     {stop, {scanner_died, Reason}, State};
 
-handle_info({'EXIT', From, Reason}, #state{db_notifier = From} = State) ->
+handle_info({'EXIT', From, Reason}, #state{event_listener = From} = State) ->
     couch_log:error("Database update notifier died. Reason: ~p", [Reason]),
     {stop, {db_update_notifier_died, Reason}, State};
 
@@ -252,7 +254,7 @@ terminate(_Reason, State) ->
     #state{
         scan_pid = ScanPid,
         rep_start_pids = StartPids,
-        db_notifier = DbNotifier
+        event_listener = Listener
     } = State,
     stop_all_replications(),
     lists:foreach(
@@ -264,7 +266,7 @@ terminate(_Reason, State) ->
     true = ets:delete(?REP_TO_STATE),
     true = ets:delete(?DOC_TO_REP),
     true = ets:delete(?DB_TO_SEQ),
-    couch_db_update_notifier:stop(DbNotifier).
+    couch_event:stop_listener(Listener).
 
 
 code_change(_OldVsn, State, _Extra) ->
@@ -309,28 +311,41 @@ has_valid_rep_id(<<?DESIGN_DOC_PREFIX, _Rest/binary>>) ->
 has_valid_rep_id(_Else) ->
     true.
 
-db_update_notifier() ->
-    Server = self(),
-    {ok, Notifier} = couch_db_update_notifier:start_link(fun
-        ({Event, DbName})
-                when Event == created; Event == updated; Event == deleted ->
-            IsRepDb = is_replicator_db(DbName),
-            case Event of
-                created when IsRepDb ->
-                    ensure_rep_ddoc_exists(DbName);
-                updated when IsRepDb ->
-                    Msg = {resume_scan, DbName},
-                    ok = gen_server:cast(Server, Msg);
-                deleted when IsRepDb ->
-                    clean_up_replications(DbName);
-                _ ->
-                    ok
-            end;
-        (_Event) ->
+
+start_event_listener() ->
+    {ok, Pid} = couch_event:link_listener(
+            ?MODULE, handle_db_event, self(), [all_dbs]
+        ),
+    Pid.
+
+
+handle_db_event(DbName, created, Server) ->
+    case is_replicator_db(DbName) of
+	true ->
+	    ensure_rep_ddoc_exists(DbName);
+	_ ->
+	    ok
+    end,
+    {ok, Server};
+handle_db_event(DbName, updated, Server) ->
+    case is_replicator_db(DbName) of
+        true ->
+	    Msg = {resume_scan, DbName},
+	    ok = gen_server:cast(Server, Msg);
+        _ ->
             ok
-        end
-    ),
-    Notifier.
+    end,
+    {ok, Server};
+handle_db_event(DbName, deleted, Server) ->
+    case is_replicator_db(DbName) of
+        true ->
+            clean_up_replications(DbName);
+        _ ->
+            ok
+    end,
+    {ok, Server};
+handle_db_event(_DbName, _Event, Server) ->
+    {ok, Server}.
 
 rescan(#state{scan_pid = nil} = State) ->
     true = ets:delete_all_objects(?DB_TO_SEQ),

http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/d6079a6f/src/couch_replicator_utils.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator_utils.erl b/src/couch_replicator_utils.erl
index dff8e50..f489ff1 100644
--- a/src/couch_replicator_utils.erl
+++ b/src/couch_replicator_utils.erl
@@ -19,6 +19,8 @@
 -export([sum_stats/2, is_deleted/1]).
 -export([mp_parse_doc/2]).
 
+-export([handle_db_event/3]).
+
 -include_lib("couch/include/couch_db.hrl").
 -include_lib("ibrowse/include/ibrowse.hrl").
 -include("couch_replicator_api_wrap.hrl").
@@ -370,21 +372,25 @@ close_db(_HttpDb) ->
 
 
 start_db_compaction_notifier(#db{name = DbName}, Server) ->
-    {ok, Notifier} = couch_db_update_notifier:start_link(
-        fun({compacted, DbName1}) when DbName1 =:= DbName ->
-                ok = gen_server:cast(Server, {db_compacted, DbName});
-            (_) ->
-                ok
-        end),
-    Notifier;
+    {ok, Pid} = couch_event:link_listener(
+            ?MODULE, handle_db_event, Server, [{dbname, DbName}]
+        ),
+    Pid;
 start_db_compaction_notifier(_, _) ->
     nil.
 
 
 stop_db_compaction_notifier(nil) ->
     ok;
-stop_db_compaction_notifier(Notifier) ->
-    couch_db_update_notifier:stop(Notifier).
+stop_db_compaction_notifier(Listener) ->
+    couch_event:stop_listener(Listener).
+
+
+handle_db_event(DbName, compacted, Server) ->
+    gen_server:cast(Server, {db_compacted, DbName}),
+    {ok, Server};
+handle_db_event(_DbName, _Event, Server) ->
+    {ok, Server}.
 
 
 sum_stats(#rep_stats{} = S1, #rep_stats{} = S2) ->


Mime
View raw message