From c661e74d2de99007804b6cb60489421d68fe406f Mon Sep 17 00:00:00 2001 From: Nick Vatamaniuc Date: Tue, 26 Jul 2016 15:22:52 -0400 Subject: [PATCH 1/2] Replace hard-coded instances of <<"_replicator">> dbs with a macro There are 3 of those. For now replace only those which refer to db names, not role. Jira: COUCHDB-3082 --- src/couch_replicator_manager.erl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/couch_replicator_manager.erl b/src/couch_replicator_manager.erl index 21d732f..dca1154 100644 --- a/src/couch_replicator_manager.erl +++ b/src/couch_replicator_manager.erl @@ -48,6 +48,7 @@ -define(AVG_ERROR_DELAY_MSEC, 100). -define(MAX_ERROR_DELAY_MSEC, 60000). -define(OWNER, <<"owner">>). +-define(REPLICATOR_DB, <<"_replicator">>). -define(DB_TO_SEQ, db_to_seq). -define(CTX, {user_ctx, #user_ctx{roles=[<<"_admin">>, <<"_replicator">>]}}). @@ -175,8 +176,8 @@ init(_) -> Epoch = make_ref(), ScanPid = spawn_link(fun() -> scan_all_dbs(Server) end), % Automatically start node local changes feed loop - ensure_rep_db_exists(<<"_replicator">>), - Pid = start_changes_reader(<<"_replicator">>, 0, Epoch), + ensure_rep_db_exists(?REPLICATOR_DB), + Pid = start_changes_reader(?REPLICATOR_DB, 0, Epoch), {ok, #state{ event_listener = start_event_listener(), scan_pid = ScanPid, @@ -951,7 +952,7 @@ scan_all_dbs(Server) when is_pid(Server) -> end, ok). is_replicator_db(DbName) -> - <<"_replicator">> =:= couch_db:dbname_suffix(DbName). + ?REPLICATOR_DB =:= couch_db:dbname_suffix(DbName). get_json_value(Key, Props) -> get_json_value(Key, Props, undefined). From 05247a26019ce5416e13ef80a12c307bdc790ee4 Mon Sep 17 00:00:00 2001 From: Nick Vatamaniuc Date: Tue, 26 Jul 2016 15:56:42 -0400 Subject: [PATCH 2/2] Replication manager's rep_start_pids now contains only {Tag, Pid} items Previously the local change feed was added to rep_start_pids as Pid only. So if replication manager stopped and terminate/2 was called before that change feed died, then ``` foreach(fun({_Tag, Pid}) -> ... end, [StartPids]) ``` would crash with a function clause error. Make sure add the replicator db name to the changes feed. Jira: COUCHDB-3082 --- src/couch_replicator_manager.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/couch_replicator_manager.erl b/src/couch_replicator_manager.erl index dca1154..0b7eeca 100644 --- a/src/couch_replicator_manager.erl +++ b/src/couch_replicator_manager.erl @@ -183,7 +183,7 @@ init(_) -> scan_pid = ScanPid, max_retries = retries_value( config:get("replicator", "max_replication_retry_count", "10")), - rep_start_pids = [Pid], + rep_start_pids = [{?REPLICATOR_DB, Pid}], live = Live, epoch = Epoch }}.