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 2023/01/06 06:51:31 UTC

[couchdb] 01/01: Fix replication job start_link.

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

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

commit 6601561611ab94accb48e229f47f31a5e83d5821
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Fri Jan 6 01:41:29 2023 -0500

    Fix replication job start_link.
    
    We don't want to register replication jobs with the module name as that
    prevents us from running more than one job at a time.
    
    This was introduced when we removed the dependence on global registrations and
    switched to using pg instead.
    
    Even more embarrassing is we didn't have tests to check multiple replication
    jobs running at the same time.
---
 .../src/couch_replicator_scheduler_job.erl         |  2 +-
 .../couch_replicator_error_reporting_tests.erl     | 25 ++++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/src/couch_replicator/src/couch_replicator_scheduler_job.erl b/src/couch_replicator/src/couch_replicator_scheduler_job.erl
index 416220efd..e16412e4a 100644
--- a/src/couch_replicator/src/couch_replicator_scheduler_job.erl
+++ b/src/couch_replicator/src/couch_replicator_scheduler_job.erl
@@ -87,7 +87,7 @@ start_link(#rep{id = Id = {BaseId, Ext}, source = Src, target = Tgt} = Rep) ->
     Target = couch_replicator_api_wrap:db_uri(Tgt),
     case couch_replicator_pg:should_start(Id, node()) of
         yes ->
-            case gen_server:start_link({local, ?MODULE}, ?MODULE, Rep, []) of
+            case gen_server:start_link(?MODULE, Rep, []) of
                 {ok, Pid} ->
                     couch_replicator_pg:join(Id, Pid),
                     {ok, Pid};
diff --git a/src/couch_replicator/test/eunit/couch_replicator_error_reporting_tests.erl b/src/couch_replicator/test/eunit/couch_replicator_error_reporting_tests.erl
index dd6609941..d9c6a1048 100644
--- a/src/couch_replicator/test/eunit/couch_replicator_error_reporting_tests.erl
+++ b/src/couch_replicator/test/eunit/couch_replicator_error_reporting_tests.erl
@@ -30,6 +30,7 @@ error_reporting_test_() ->
             ?TDEF_FE(t_fail_changes_manager),
             ?TDEF_FE(t_fail_changes_reader_proc),
             ?TDEF_FE(t_dont_start_duplicate_job),
+            ?TDEF_FE(t_can_start_multiple_jobs),
             ?TDEF_FE(t_stop_duplicate_job)
         ]
     }.
@@ -160,6 +161,30 @@ t_dont_start_duplicate_job({_Ctx, {Source, Target}}) ->
     ExpectErr = {error, {already_started, Pid}},
     ?assertEqual(ExpectErr, couch_replicator_scheduler_job:start_link(Rep)).
 
+t_can_start_multiple_jobs({_Ctx, {Source, Target1}}) ->
+    Target2 = couch_replicator_test_helper:setup_db(),
+    populate_db(Source, 1, 5),
+
+    {ok, RepId1} = replicate(Source, Target1),
+    {ok, RepId2} = replicate(Source, Target2),
+    RepPid1 = couch_replicator_test_helper:get_pid(RepId1),
+    RepPid2 = couch_replicator_test_helper:get_pid(RepId2),
+    ?assert(is_pid(RepPid1)),
+    ?assert(is_pid(RepPid2)),
+
+    ?assert(is_process_alive(RepPid1)),
+    ?assert(is_process_alive(RepPid2)),
+
+    wait_target_in_sync(Source, Target1),
+    wait_target_in_sync(Source, Target2),
+
+    ?assert(is_process_alive(RepPid1)),
+    ?assert(is_process_alive(RepPid2)),
+
+    exit(RepPid1, kill),
+    exit(RepPid2, kill),
+    couch_replicator_test_helper:teardown_db(Target2).
+
 t_stop_duplicate_job({_Ctx, {Source, Target}}) ->
     {ok, RepId} = replicate(Source, Target),
     wait_target_in_sync(Source, Target),