couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kocol...@apache.org
Subject svn commit: r807360 - /couchdb/trunk/src/couchdb/couch_rep.erl
Date Mon, 24 Aug 2009 20:10:20 GMT
Author: kocolosk
Date: Mon Aug 24 20:10:19 2009
New Revision: 807360

URL: http://svn.apache.org/viewvc?rev=807360&view=rev
Log:
only save a checkpoint at the end if something changed

Modified:
    couchdb/trunk/src/couchdb/couch_rep.erl

Modified: couchdb/trunk/src/couchdb/couch_rep.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_rep.erl?rev=807360&r1=807359&r2=807360&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_rep.erl (original)
+++ couchdb/trunk/src/couchdb/couch_rep.erl Mon Aug 24 20:10:19 2009
@@ -171,6 +171,7 @@
 
 handle_info({writer_checkpoint, SourceSeq}, #state{committed_seq=N} = State)
         when SourceSeq > N ->
+    ?LOG_DEBUG("SourceSeq ~p N ~p", [SourceSeq, N]),
     MissingRevs = State#state.missing_revs,
     ok = gen_server:cast(MissingRevs, {update_committed_seq, SourceSeq}),
     couch_task_status:update("W Processed source update #~p", [SourceSeq]),
@@ -196,43 +197,12 @@
     ?LOG_ERROR("exit of linked Pid ~p with reason ~p", [Pid, Reason]),
     {stop, Reason, State}.
 
-terminate(normal, State) ->
-    #state{
-        checkpoint_scheduled = TRef,
-        checkpoint_history = CheckpointHistory,
-        committed_seq = NewSeq,
-        listeners = Listeners,
-        source = Source,
-        target = Target,
-        stats = Stats,
-        source_log = #doc{body={OldHistory}}
-    } = do_checkpoint(State),
-    timer:cancel(TRef),
-    couch_task_status:update("Finishing"),
-    ets:delete(Stats),
-    close_db(Target),
+terminate(normal, #state{checkpoint_scheduled=nil} = State) ->
+    do_terminate(State);
     
-    NewRepHistory = case CheckpointHistory of
-    nil ->
-        {[{<<"no_changes">>, true} | OldHistory]};
-    _Else ->
-        CheckpointHistory
-    end,
-
-    %% reply to original requester
-    [Original|OtherListeners] = lists:reverse(Listeners),
-    gen_server:reply(Original, {ok, NewRepHistory}),
-
-    %% maybe trigger another replication. If this replicator uses a local
-    %% source Db, changes to that Db since we started will not be included in
-    %% this pass.
-    case up_to_date(Source, NewSeq) of
-        true ->
-            [gen_server:reply(R, {ok, NewRepHistory}) || R <- OtherListeners];
-        false ->
-            [gen_server:reply(R, retry) || R <- OtherListeners]
-    end,
-    close_db(Source);
+terminate(normal, State) ->
+    timer:cancel(State#state.checkpoint_scheduled),
+    do_terminate(do_checkpoint(State));
 
 terminate(Reason, State) ->
     #state{
@@ -340,6 +310,42 @@
     {ok, Info} = couch_db:get_db_info(Db),
     Info.
 
+do_terminate(State) ->
+    #state{
+        checkpoint_history = CheckpointHistory,
+        committed_seq = NewSeq,
+        listeners = Listeners,
+        source = Source,
+        target = Target,
+        stats = Stats,
+        source_log = #doc{body={OldHistory}}
+    } = State,
+    couch_task_status:update("Finishing"),
+    ets:delete(Stats),
+    close_db(Target),
+    
+    NewRepHistory = case CheckpointHistory of
+    nil ->
+        {[{<<"no_changes">>, true} | OldHistory]};
+    _Else ->
+        CheckpointHistory
+    end,
+
+    %% reply to original requester
+    [Original|OtherListeners] = lists:reverse(Listeners),
+    gen_server:reply(Original, {ok, NewRepHistory}),
+
+    %% maybe trigger another replication. If this replicator uses a local
+    %% source Db, changes to that Db since we started will not be included in
+    %% this pass.
+    case up_to_date(Source, NewSeq) of
+        true ->
+            [gen_server:reply(R, {ok, NewRepHistory}) || R <- OtherListeners];
+        false ->
+            [gen_server:reply(R, retry) || R <- OtherListeners]
+    end,
+    close_db(Source).
+
 has_session_id(_SessionId, []) ->
     false;
 has_session_id(SessionId, [{Props} | Rest]) ->



Mime
View raw message