couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [44/44] couch-replicator commit: updated refs/heads/63012-defensive to 1afa5ea
Date Tue, 07 Jun 2016 11:05:48 GMT
Remove defensive programming

We now explicitly demonitor, so we should never get a DOWN message
unless we have a job with a pid.


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

Branch: refs/heads/63012-defensive
Commit: 1afa5ea0cfe1375e44035d00d8c1dbb31b06ecf8
Parents: 5ca0376
Author: Robert Newson <rnewson@apache.org>
Authored: Tue Jun 7 12:04:08 2016 +0100
Committer: Robert Newson <rnewson@apache.org>
Committed: Tue Jun 7 12:04:08 2016 +0100

----------------------------------------------------------------------
 src/couch_replicator_scheduler.erl | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/1afa5ea0/src/couch_replicator_scheduler.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator_scheduler.erl b/src/couch_replicator_scheduler.erl
index 851aae9..8e30806 100644
--- a/src/couch_replicator_scheduler.erl
+++ b/src/couch_replicator_scheduler.erl
@@ -126,27 +126,19 @@ handle_info(reschedule, State) ->
     {noreply, State#state{timer = Timer}};
 
 handle_info({'DOWN', _Ref, process, Pid, normal}, State) ->
-    case job_by_pid(Pid) of
-        {ok, #job{}=Job} ->
-            remove_job_int(Job);
-        _Else ->
-            ok
-    end,
+    {ok, Job} = job_by_pid(Pid),
+    couch_log:notice("~p: Job ~p completed normally", [?MODULE, Job#job.id]),
+    remove_job_int(Job),
     {noreply, State};
 
 handle_info({'DOWN', _Ref, process, Pid, Reason}, State) ->
-    case job_by_pid(Pid) of
-        {ok, #job{}=Job0} ->
-            couch_log:notice("~p: Job ~p died with reason: ~p",
-                             [?MODULE, Job0#job.id, Reason]),
-            Job1 = update_history(Job0#job{pid = undefined}, crashed, os:timestamp()),
-            true = ets:insert(?MODULE, Job1),
-            start_pending_jobs(State#state.max_jobs),
-            {noreply, State};
-        {error, not_found} ->
-            % removed in remove_job and should not be reinserted.
-            {noreply, State}
-    end;
+    {ok, Job0} = job_by_pid(Pid),
+    couch_log:notice("~p: Job ~p died with reason: ~p",
+        [?MODULE, Job0#job.id, Reason]),
+    Job1 = update_history(Job0#job{pid = undefined}, crashed, os:timestamp()),
+    true = ets:insert(?MODULE, Job1),
+    start_pending_jobs(State#state.max_jobs),
+    {noreply, State};
 
 handle_info(_, State) ->
     {noreply, State}.
@@ -257,6 +249,7 @@ stop_job_int(#job{pid = undefined}) ->
 
 stop_job_int(#job{} = Job0) ->
     ok = couch_replicator_scheduler_sup:terminate_child(Job0#job.pid),
+    demonitor(Job0#job.pid, [flush]),
     Job1 = update_history(Job0#job{pid = undefined}, stopped, os:timestamp()),
     true = ets:insert(?MODULE, Job1),
     couch_log:notice("~p: Job ~p stopped as ~p",


Mime
View raw message