Author: fdmanana
Date: Mon Sep 19 04:05:52 2011
New Revision: 1172418
URL: http://svn.apache.org/viewvc?rev=1172418&view=rev
Log:
Update replication task status more often
The task status for a replication is now updated more
often. It also avoids the case where the reported
progress was greater than 100%.
Modified:
couchdb/trunk/src/couchdb/couch_api_wrap.erl
couchdb/trunk/src/couchdb/couch_replicator.erl
couchdb/trunk/test/etap/240-replication-compact.t
Modified: couchdb/trunk/src/couchdb/couch_api_wrap.erl
URL:
http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_api_wrap.erl?rev=1172418&r1=1172417&r2=1172418&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_api_wrap.erl (original)
+++ couchdb/trunk/src/couchdb/couch_api_wrap.erl Mon Sep 19 04:05:52 2011
@@ -112,8 +112,10 @@ get_db_info(#httpdb{} = Db) ->
fun(200, _, {Props}) ->
{ok, Props}
end);
-get_db_info(Db) ->
+get_db_info(#db{name = DbName, user_ctx = UserCtx}) ->
+ {ok, Db} = couch_db:open(DbName, [{user_ctx, UserCtx}]),
{ok, Info} = couch_db:get_db_info(Db),
+ couch_db:close(Db),
{ok, [{couch_util:to_binary(K), V} || {K, V} <- Info]}.
Modified: couchdb/trunk/src/couchdb/couch_replicator.erl
URL:
http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_replicator.erl?rev=1172418&r1=1172417&r2=1172418&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_replicator.erl (original)
+++ couchdb/trunk/src/couchdb/couch_replicator.erl Mon Sep 19 04:05:52 2011
@@ -651,7 +651,10 @@ checkpoint_interval(_State) ->
5000.
do_checkpoint(#rep_state{current_through_seq=Seq, committed_seq=Seq} = State)
->
- {ok, State};
+ SourceCurSeq = source_cur_seq(State),
+ NewState = State#rep_state{source_seq = SourceCurSeq},
+ update_task(NewState),
+ {ok, NewState};
do_checkpoint(State) ->
#rep_state{
source_name=SourceName,
@@ -725,7 +728,9 @@ do_checkpoint(State) ->
Source, SourceLog#doc{body = NewRepHistory}, source),
{TgtRevPos, TgtRevId} = update_checkpoint(
Target, TargetLog#doc{body = NewRepHistory}, target),
+ SourceCurSeq = source_cur_seq(State),
NewState = State#rep_state{
+ source_seq = SourceCurSeq,
checkpoint_history = NewRepHistory,
committed_seq = NewTsSeq,
source_log = SourceLog#doc{revs={SrcRevPos, [SrcRevId]}},
Modified: couchdb/trunk/test/etap/240-replication-compact.t
URL:
http://svn.apache.org/viewvc/couchdb/trunk/test/etap/240-replication-compact.t?rev=1172418&r1=1172417&r2=1172418&view=diff
==============================================================================
--- couchdb/trunk/test/etap/240-replication-compact.t (original)
+++ couchdb/trunk/test/etap/240-replication-compact.t Mon Sep 19 04:05:52 2011
@@ -68,7 +68,7 @@ target_db_name() -> <<"couch_test_rep_db
main(_) ->
test_util:init_code_path(),
- etap:plan(360),
+ etap:plan(368),
case (catch test()) of
ok ->
etap:end_tests();
@@ -101,12 +101,12 @@ test() ->
"Target database is idle before starting replication"),
{ok, RepPid, RepId} = replicate(Source, Target),
- check_active_tasks(RepPid, RepId, Source, Target),
+ check_active_tasks(RepPid, RepId, Source, Target, false),
{ok, DocsWritten} = populate_and_compact_test(
RepPid, SourceDb, TargetDb),
wait_target_in_sync(DocsWritten, TargetDb),
- check_active_tasks(RepPid, RepId, Source, Target),
+ check_active_tasks(RepPid, RepId, Source, Target, true),
cancel_replication(RepId, RepPid),
compare_dbs(SourceDb, TargetDb),
@@ -269,7 +269,7 @@ compare_dbs(#db{name = SourceName}, #db{
ok = couch_db:close(TargetDb).
-check_active_tasks(RepPid, {BaseId, Ext} = _RepId, Src, Tgt) ->
+check_active_tasks(RepPid, {BaseId, Ext} = _RepId, Src, Tgt, AtEnd) ->
Source = case Src of
{remote, NameSrc} ->
<<(db_url(NameSrc))/binary, $/>>;
@@ -284,6 +284,13 @@ check_active_tasks(RepPid, {BaseId, Ext}
end,
FullRepId = list_to_binary(BaseId ++ Ext),
Pid = list_to_binary(pid_to_list(RepPid)),
+ case AtEnd of
+ true ->
+ % wait for checkpoint to make sure we get a progress of 100% reported
+ ok = timer:sleep(5000);
+ false ->
+ ok
+ end,
[RepTask] = couch_task_status:all(),
etap:is(couch_util:get_value(pid, RepTask), Pid,
"_active_tasks entry has correct pid property"),
@@ -308,7 +315,15 @@ check_active_tasks(RepPid, {BaseId, Ext}
etap:is(is_integer(couch_util:get_value(checkpointed_source_seq,
RepTask)), true,
"_active_tasks entry has integer checkpointed_source_seq property"),
etap:is(is_integer(couch_util:get_value(source_seq, RepTask)), true,
- "_active_tasks entry has integer source_seq property").
+ "_active_tasks entry has integer source_seq property"),
+ case AtEnd of
+ true ->
+ etap:is(couch_util:get_value(progress, RepTask), 100,
+ "_active_tasks entry has a progress of 100%");
+ false ->
+ etap:is(is_integer(couch_util:get_value(progress, RepTask)), true,
+ "_active_tasks entry has an integer progress property")
+ end.
wait_writer(Pid, NumDocs) ->