You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2019/08/14 10:38:04 UTC

[GitHub] [couchdb] iilyak commented on a change in pull request #2111: Fix replication rescheduling Running < MaxJobs corner case

iilyak commented on a change in pull request #2111: Fix replication rescheduling Running < MaxJobs corner case
URL: https://github.com/apache/couchdb/pull/2111#discussion_r313810037
 
 

 ##########
 File path: src/couch_replicator/src/couch_replicator_scheduler.erl
 ##########
 @@ -723,49 +726,45 @@ reset_job_process(#job{} = Job) ->
 
 -spec reschedule(#state{}) -> ok.
 reschedule(State) ->
-    Running = running_job_count(),
-    Pending = pending_job_count(),
-    stop_excess_jobs(State, Running),
-    start_pending_jobs(State, Running, Pending),
-    rotate_jobs(State, Running, Pending),
-    update_running_jobs_stats(State#state.stats_pid),
-    ok.
+    StopCount = stop_excess_jobs(State, running_job_count()),
+    rotate_jobs(State, StopCount),
+    update_running_jobs_stats(State#state.stats_pid).
 
 
--spec stop_excess_jobs(#state{}, non_neg_integer()) -> ok.
+-spec stop_excess_jobs(#state{}, non_neg_integer()) -> non_neg_integer().
 stop_excess_jobs(State, Running) ->
     #state{max_jobs=MaxJobs} = State,
-    StopCount = Running - MaxJobs,
-    if StopCount =< 0 -> ok; true ->
-        Stopped = stop_jobs(StopCount, true, State),
-        OneshotLeft = StopCount - Stopped,
-        if OneshotLeft =< 0 -> ok; true ->
-            stop_jobs(OneshotLeft, false, State),
-            ok
-        end
-    end.
+    StopCount = max(0, Running - MaxJobs),
+    Stopped = stop_jobs(StopCount, true, State),
+    OneshotLeft = StopCount - Stopped,
 
 Review comment:
   I think we should either change this line to `max(0, StopCount - Stopped)` or update stop_jobs to handle (return 0) negative values. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services