You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ko...@apache.org on 2011/10/26 20:05:34 UTC

[48/50] git commit: Update replication task status more often

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


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/e32ac059
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/e32ac059
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/e32ac059

Branch: refs/heads/1319-large-headers-are-corrupted
Commit: e32ac0598c0860f0ad350cc791450ea686e3edbe
Parents: 06fb18a
Author: Filipe David Borba Manana <fd...@apache.org>
Authored: Mon Sep 19 04:05:52 2011 +0000
Committer: Filipe David Borba Manana <fd...@apache.org>
Committed: Mon Sep 19 04:05:52 2011 +0000

----------------------------------------------------------------------
 src/couchdb/couch_api_wrap.erl      |    4 +++-
 src/couchdb/couch_replicator.erl    |    7 ++++++-
 test/etap/240-replication-compact.t |   25 ++++++++++++++++++++-----
 3 files changed, 29 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/e32ac059/src/couchdb/couch_api_wrap.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_api_wrap.erl b/src/couchdb/couch_api_wrap.erl
index 19f476a..9e27e7d 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]}.
 
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/e32ac059/src/couchdb/couch_replicator.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_replicator.erl b/src/couchdb/couch_replicator.erl
index c2e793e..315cec4 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]}},

http://git-wip-us.apache.org/repos/asf/couchdb/blob/e32ac059/test/etap/240-replication-compact.t
----------------------------------------------------------------------
diff --git a/test/etap/240-replication-compact.t b/test/etap/240-replication-compact.t
index 6d09f04..d025a65 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) ->