You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2019/10/22 20:01:12 UTC

[couchdb] branch replicator-job-churn-fix updated (036ade3 -> c34b417)

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a change to branch replicator-job-churn-fix
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


 discard 036ade3  Avoid churning replication jobs if there is enough room to run pending jobs
     new c34b417  Avoid churning replication jobs if there is enough room to run pending jobs

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (036ade3)
            \
             N -- N -- N   refs/heads/replicator-job-churn-fix (c34b417)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/couch_replicator/src/couch_replicator_scheduler.erl | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)


[couchdb] 01/01: Avoid churning replication jobs if there is enough room to run pending jobs

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch replicator-job-churn-fix
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit c34b417d6f4ace0fdad8438127ebc99791b4d70e
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Tue Oct 22 14:27:13 2019 -0400

    Avoid churning replication jobs if there is enough room to run pending jobs
    
    When rescheduling jobs, make sure to stops existing job as much as needed to
    make room for the pending jobs.
---
 .../src/couch_replicator_scheduler.erl             | 38 ++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)

diff --git a/src/couch_replicator/src/couch_replicator_scheduler.erl b/src/couch_replicator/src/couch_replicator_scheduler.erl
index 7fe417a..0e60fed 100644
--- a/src/couch_replicator/src/couch_replicator_scheduler.erl
+++ b/src/couch_replicator/src/couch_replicator_scheduler.erl
@@ -760,8 +760,12 @@ rotate_jobs(State, ChurnSoFar) ->
     % Reduce MaxChurn by the number of already stopped jobs in the
     % current rescheduling cycle.
     Churn = max(0, MaxChurn - ChurnSoFar),
-    if Running =< MaxJobs ->
-        StopCount = lists:min([Pending, Running, Churn]),
+    SlotsAvailable = MaxJobs - Running,
+    if SlotsAvailable >= 0 ->
+        % If there is are enough SlotsAvailable reduce StopCount to avoid
+        % unnesessarily stopping jobs. `stop_jobs/3` ignores 0 or negaive
+        % values so we don't worry about that here.
+        StopCount = lists:min([Pending - SlotsAvailable, Running, Churn]),
         stop_jobs(StopCount, true, State),
         StartCount = max(0, MaxJobs - running_job_count()),
         start_jobs(StartCount, State);
@@ -1047,6 +1051,8 @@ scheduler_test_() ->
             t_stop_oldest_first(),
             t_start_oldest_first(),
             t_jobs_churn_even_if_not_all_max_jobs_are_running(),
+            t_jobs_dont_churn_if_there_are_available_running_slots(),
+            t_start_only_pending_jobs_do_not_churn_existing_ones(),
             t_dont_stop_if_nothing_pending(),
             t_max_churn_limits_number_of_rotated_jobs(),
             t_existing_jobs(),
@@ -1207,11 +1213,39 @@ t_jobs_churn_even_if_not_all_max_jobs_are_running() ->
             continuous(5)
         ]),
         reschedule(mock_state(2, 2)),
+        % 7 would stop running and 2 and 5 will start since they will be the
+        % oldest pending jobs
         ?assertEqual({2, 1}, run_stop_count()),
         ?assertEqual([7], jobs_stopped())
     end).
 
 
+t_jobs_dont_churn_if_there_are_available_running_slots() ->
+     ?_test(begin
+        setup_jobs([
+            continuous_running(1),
+            continuous_running(2)
+        ]),
+        reschedule(mock_state(2, 2)),
+        ?assertEqual({2, 0}, run_stop_count()),
+        ?assertEqual([], jobs_stopped()),
+        ?assertEqual(0, meck:num_calls(couch_replicator_scheduler_sup, start_child, 1))
+    end).
+
+
+t_start_only_pending_jobs_do_not_churn_existing_ones() ->
+     ?_test(begin
+        setup_jobs([
+            continuous(1),
+            continuous_running(2)
+        ]),
+        reschedule(mock_state(2, 2)),
+        ?assertEqual(1, meck:num_calls(couch_replicator_scheduler_sup, start_child, 1)),
+        ?assertEqual([], jobs_stopped()),
+        ?assertEqual({2, 0}, run_stop_count())
+    end).
+
+
 t_dont_stop_if_nothing_pending() ->
     ?_test(begin
         setup_jobs([continuous_running(1), continuous_running(2)]),