nickva commented on a change in pull request #470: Scheduling Replicator URL: https://github.com/apache/couchdb/pull/470#discussion_r112765656
########## File path: src/couch_replicator/src/couch_replicator_scheduler_job.erl ########## @@ -0,0 +1,969 @@ +% Licensed under the Apache License, Version 2.0 (the "License"); you may not +% use this file except in compliance with the License. You may obtain a copy of +% the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +% License for the specific language governing permissions and limitations under +% the License. + +-module(couch_replicator_scheduler_job). + +-behaviour(gen_server). + +-export([ + start_link/1 +]). + +-export([ + init/1, + terminate/2, + handle_call/3, + handle_info/2, + handle_cast/2, + code_change/3, + format_status/2 +]). + +-include_lib("couch/include/couch_db.hrl"). +-include("couch_replicator_api_wrap.hrl"). +-include("couch_replicator_scheduler.hrl"). +-include("couch_replicator.hrl"). + +-import(couch_util, [ + get_value/2, + get_value/3, + to_binary/1 +]). + +-import(couch_replicator_utils, [ + start_db_compaction_notifier/2, + stop_db_compaction_notifier/1, + pp_rep_id/1 +]). + + +-define(LOWEST_SEQ, 0). +-define(DEFAULT_CHECKPOINT_INTERVAL, 30000). +-define(STARTUP_JITTER_DEFAULT, 5000). + +-record(rep_state, { + rep_details, + source_name, + target_name, + source, + target, + history, + checkpoint_history, + start_seq, + committed_seq, + current_through_seq, + seqs_in_progress = [], + highest_seq_done = {0, ?LOWEST_SEQ}, + source_log, + target_log, + rep_starttime, + src_starttime, + tgt_starttime, + timer, % checkpoint timer + changes_queue, + changes_manager, + changes_reader, + workers, + stats = couch_replicator_stats:new(), + session_id, + source_db_compaction_notifier = nil, + target_db_compaction_notifier = nil, + source_monitor = nil, + target_monitor = nil, + source_seq = nil, + use_checkpoints = true, + checkpoint_interval = ?DEFAULT_CHECKPOINT_INTERVAL, + type = db, + view = nil +}). + + +start_link(#rep{id = {BaseId, Ext}, source = Src, target = Tgt} = Rep) -> + RepChildId = BaseId ++ Ext, + Source = couch_replicator_api_wrap:db_uri(Src), + Target = couch_replicator_api_wrap:db_uri(Tgt), + ServerName = {global, {?MODULE, Rep#rep.id}}, + + case gen_server:start_link(ServerName, ?MODULE, Rep, []) of + {ok, Pid} -> + couch_log:notice("starting new replication `~s` at ~p (`~s` -> `~s`)", + [RepChildId, Pid, Source, Target]), + {ok, Pid}; + {error, Reason} -> + couch_log:warning("failed to start replication `~s` (`~s` -> `~s`)", + [RepChildId, Source, Target]), + {error, Reason} + end. + + +init(InitArgs) -> + {ok, InitArgs, 0}. Review comment: This was another direct copy from previous code: https://github.com/apache/couchdb/blob/master/src/couch_replicator/src/couch_replicator.erl#L253-L256 The code for replication task used to live in couch_replicator.erl then just moved largely unmodified `couch_replicator_scheduler_jobs.erl` so it's been like this for a long time. 50/50 on this as well, as modifying this might cause some unintended consequences. But I'll give it a try. Seems easy enough ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
