summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/couch/src/couch_rep.erl31
-rw-r--r--apps/couch/src/couch_replication_manager.erl2
2 files changed, 15 insertions, 18 deletions
diff --git a/apps/couch/src/couch_rep.erl b/apps/couch/src/couch_rep.erl
index 761fbd76..1aade18f 100644
--- a/apps/couch/src/couch_rep.erl
+++ b/apps/couch/src/couch_rep.erl
@@ -15,9 +15,9 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
code_change/3]).
--export([replicate/2, replicate/3, checkpoint/1]).
+-export([replicate/2, checkpoint/1]).
-export([make_replication_id/2]).
--export([start_replication/4, end_replication/1, get_result/4]).
+-export([start_replication/3, end_replication/1, get_result/4]).
-include("couch_db.hrl").
-include("couch_js_functions.hrl").
@@ -66,16 +66,13 @@ replicate(Source, Target) when is_binary(Source), is_binary(Target) ->
replicate({[{<<"source">>, Source}, {<<"target">>, Target}]}, #user_ctx{});
%% function handling POST to _replicate
-replicate(PostBody, UserCtx) ->
- replicate(PostBody, UserCtx, couch_replication_manager).
-
-replicate({Props}=PostBody, UserCtx, Module) ->
+replicate({Props}=PostBody, UserCtx) ->
RepId = make_replication_id(PostBody, UserCtx),
case couch_util:get_value(<<"cancel">>, Props, false) of
true ->
end_replication(RepId);
false ->
- Server = start_replication(PostBody, RepId, UserCtx, Module),
+ Server = start_replication(PostBody, RepId, UserCtx),
get_result(Server, RepId, PostBody, UserCtx)
end.
@@ -95,11 +92,11 @@ end_replication({BaseId, Extension}) ->
end
end.
-start_replication(RepDoc, {BaseId, Extension} = RepId, UserCtx, Module) ->
+start_replication(RepDoc, {BaseId, Extension} = RepId, UserCtx) ->
Replicator = {
BaseId ++ Extension,
{gen_server, start_link,
- [?MODULE, [RepId, RepDoc, UserCtx, Module], []]},
+ [?MODULE, [RepId, RepDoc, UserCtx], []]},
temporary,
1,
worker,
@@ -136,7 +133,7 @@ init(InitArgs) ->
{stop, Error}
end.
-do_init([{BaseId, _Ext} = RepId, {PostProps}, UserCtx, Module] = InitArgs) ->
+do_init([{BaseId, _Ext} = RepId, {PostProps}, UserCtx] = InitArgs) ->
process_flag(trap_exit, true),
SourceProps = couch_util:get_value(<<"source">>, PostProps),
@@ -177,7 +174,7 @@ do_init([{BaseId, _Ext} = RepId, {PostProps}, UserCtx, Module] = InitArgs) ->
couch_task_status:add_task("Replication", io_lib:format("~s: ~s -> ~s",
[ShortId, dbname(Source), dbname(Target)]), "Starting"),
- Module:replication_started(RepId),
+ couch_replication_manager:replication_started(RepId),
State = #state{
changes_feed = ChangesFeed,
@@ -272,24 +269,24 @@ handle_info({'EXIT', _Pid, {Err, Reason}}, State) when Err == source_error;
handle_info({'EXIT', _Pid, Reason}, State) ->
{stop, Reason, State}.
-terminate(normal, #state{checkpoint_scheduled=nil, init_args=[RepId, _, _, Module]} = State) ->
+terminate(normal, #state{checkpoint_scheduled=nil, init_args=[RepId | _]} = State) ->
do_terminate(State),
- Module:replication_completed(RepId);
+ couch_replication_manager:replication_completed(RepId);
-terminate(normal, #state{init_args=[RepId, _, _, Module]} = State) ->
+terminate(normal, #state{init_args=[RepId | _]} = State) ->
timer:cancel(State#state.checkpoint_scheduled),
do_terminate(do_checkpoint(State)),
- Module:replication_completed(RepId);
+ couch_replication_manager:replication_completed(RepId);
terminate(shutdown, #state{listeners = Listeners} = State) ->
% continuous replication stopped
[gen_server:reply(L, {ok, stopped}) || L <- Listeners],
terminate_cleanup(State);
-terminate(Reason, #state{listeners = Listeners, init_args=[RepId, _, _, Module]} = State) ->
+terminate(Reason, #state{listeners = Listeners, init_args=[RepId | _]} = State) ->
[gen_server:reply(L, {error, Reason}) || L <- Listeners],
terminate_cleanup(State),
- Module:replication_error(RepId, Reason).
+ couch_replication_manager:replication_error(RepId, Reason).
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
diff --git a/apps/couch/src/couch_replication_manager.erl b/apps/couch/src/couch_replication_manager.erl
index 3715cea1..6ced17e4 100644
--- a/apps/couch/src/couch_replication_manager.erl
+++ b/apps/couch/src/couch_replication_manager.erl
@@ -408,7 +408,7 @@ maybe_tag_rep_doc(DocId, {RepProps}, RepId) ->
start_replication(Server, RepDoc, RepId, UserCtx, Wait) ->
ok = timer:sleep(Wait * 1000),
- case (catch couch_rep:start_replication(RepDoc, RepId, UserCtx, ?MODULE)) of
+ case (catch couch_rep:start_replication(RepDoc, RepId, UserCtx)) of
Pid when is_pid(Pid) ->
ok = gen_server:call(Server, {rep_started, RepId}, infinity),
couch_rep:get_result(Pid, RepId, RepDoc, UserCtx);