diff options
author | Filipe David Borba Manana <fdmanana@apache.org> | 2011-09-19 04:05:52 +0000 |
---|---|---|
committer | Filipe David Borba Manana <fdmanana@apache.org> | 2011-09-19 04:05:52 +0000 |
commit | e32ac0598c0860f0ad350cc791450ea686e3edbe (patch) | |
tree | d26aa61b58816b545ef82251d4fa64bedc71bc6f | |
parent | 06fb18a149c97b101067258417f0edecb245bcbe (diff) | |
download | couchdb-e32ac0598c0860f0ad350cc791450ea686e3edbe.tar.gz |
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%.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1172418 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/couchdb/couch_api_wrap.erl | 4 | ||||
-rw-r--r-- | src/couchdb/couch_replicator.erl | 7 | ||||
-rwxr-xr-x | test/etap/240-replication-compact.t | 25 |
3 files changed, 29 insertions, 7 deletions
diff --git a/src/couchdb/couch_api_wrap.erl b/src/couchdb/couch_api_wrap.erl index 19f476a06..9e27e7dad 100644 --- a/src/couchdb/couch_api_wrap.erl +++ b/src/couchdb/couch_api_wrap.erl @@ -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]}. diff --git a/src/couchdb/couch_replicator.erl b/src/couchdb/couch_replicator.erl index c2e793e8d..315cec404 100644 --- a/src/couchdb/couch_replicator.erl +++ b/src/couchdb/couch_replicator.erl @@ -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]}}, diff --git a/test/etap/240-replication-compact.t b/test/etap/240-replication-compact.t index 6d09f04f9..d025a658e 100755 --- a/test/etap/240-replication-compact.t +++ b/test/etap/240-replication-compact.t @@ -68,7 +68,7 @@ target_db_name() -> <<"couch_test_rep_db_b">>. 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{name = TargetName}) -> 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} = _RepId, Src, Tgt) -> 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} = _RepId, Src, Tgt) -> 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) -> |