Repository: couchdb-couch-replicator Updated Branches: refs/heads/master f67ebff22 -> 0248d231d
Update handle_config_terminate API COUCHDB-3102 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/33d386fa Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/tree/33d386fa Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/diff/33d386fa Branch: refs/heads/master Commit: 33d386fae3d30bba3e88ab6f01f899a98f28fe4e Parents: f67ebff Author: ILYA Khlopotov <[email protected]> Authored: Fri Aug 19 16:10:24 2016 -0700 Committer: ILYA Khlopotov <[email protected]> Committed: Tue Aug 23 12:39:13 2016 -0700 ---------------------------------------------------------------------- src/couch_replicator_manager.erl | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/33d386fa/src/couch_replicator_manager.erl ---------------------------------------------------------------------- diff --git a/src/couch_replicator_manager.erl b/src/couch_replicator_manager.erl index eed72b8..953b1bf 100644 --- a/src/couch_replicator_manager.erl +++ b/src/couch_replicator_manager.erl @@ -12,7 +12,7 @@ -module(couch_replicator_manager). -behaviour(gen_server). --vsn(2). +-vsn(3). -behaviour(config_listener). % public API @@ -55,6 +55,8 @@ -define(replace(L, K, V), lists:keystore(K, 1, L, {K, V})). +-define(RELISTEN_DELAY, 5000). + -record(rep_state, { rep, starting, @@ -143,17 +145,15 @@ continue(#rep{id = RepId}) -> handle_config_change("replicator", "max_replication_retry_count", V, _, S) -> - ok = gen_server:cast(S, {set_max_retries, retries_value(V)}), + ok = gen_server:cast(?MODULE, {set_max_retries, retries_value(V)}), {ok, S}; handle_config_change(_, _, _, _, S) -> {ok, S}. -handle_config_terminate(_, stop, _) -> ok; -handle_config_terminate(Self, _, _) -> - spawn(fun() -> - timer:sleep(5000), - config:listen_for_changes(?MODULE, Self) - end). +handle_config_terminate(_, stop, _) -> + ok; +handle_config_terminate(_Server, _Reason, _State) -> + erlang:send_after(?RELISTEN_DELAY, whereis(?MODULE), restart_config_listener). init(_) -> process_flag(trap_exit, true), @@ -163,7 +163,7 @@ init(_) -> ?REP_TO_STATE = ets:new(?REP_TO_STATE, [named_table, set, public]), ?DB_TO_SEQ = ets:new(?DB_TO_SEQ, [named_table, set, public]), Server = self(), - ok = config:listen_for_changes(?MODULE, Server), + ok = config:listen_for_changes(?MODULE, nil), Epoch = make_ref(), ScanPid = spawn_link(fun() -> scan_all_dbs(Server) end), % Automatically start node local changes feed loop @@ -330,6 +330,10 @@ handle_info({'DOWN', _Ref, _, _, _}, State) -> handle_info(shutdown, State) -> {stop, shutdown, State}; +handle_info(restart_config_listener, State) -> + ok = config:listen_for_changes(?MODULE, nil), + {noreply, State}; + handle_info(Msg, State) -> couch_log:error("Replication manager received unexpected message ~p", [Msg]), {stop, {unexpected_msg, Msg}, State}.
