You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2017/05/22 17:09:03 UTC

[couchdb] branch master updated: Skip internal replication if changes already replicated

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git

The following commit(s) were added to refs/heads/master by this push:
       new  a9ad342   Skip internal replication if changes already replicated
a9ad342 is described below

commit a9ad3429e7c40c9b4ec387fdb84567e5a67f8099
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Mon May 22 11:36:53 2017 -0400

    Skip internal replication if changes already replicated
    
    If minimum checkpointed sequence is greater or equal to source db sequence,
    do not start an internal replication task. The typical case is when checkpoint
    sequence is equal to the db sequence. Previously replication task was started
    always wrote a checkpoint document even if no database changes. This resulted
    in a flurry of writes during cluster startup.
---
 src/mem3/src/mem3_rep.erl | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/mem3/src/mem3_rep.erl b/src/mem3/src/mem3_rep.erl
index ad7ac55..db09d36 100644
--- a/src/mem3/src/mem3_rep.erl
+++ b/src/mem3/src/mem3_rep.erl
@@ -173,10 +173,16 @@ find_source_seq_int(#doc{body={Props}}, SrcNode0, TgtNode0, TgtUUID, TgtSeq) ->
 repl(#db{name=DbName, seq_tree=Bt}=Db, Acc0) ->
     erlang:put(io_priority, {internal_repl, DbName}),
     #acc{seq=Seq} = Acc1 = calculate_start_seq(Acc0#acc{source = Db}),
-    Fun = fun ?MODULE:changes_enumerator/3,
-    {ok, _, Acc2} = couch_btree:fold(Bt, Fun, Acc1, [{start_key, Seq + 1}]),
-    {ok, #acc{seq = LastSeq}} = replicate_batch(Acc2),
-    {ok, couch_db:count_changes_since(Db, LastSeq)}.
+    case Seq >= couch_db:get_update_seq(Db) of
+        true ->
+            {ok, 0};
+        false ->
+            Fun = fun ?MODULE:changes_enumerator/3,
+            FoldOpts =  [{start_key, Seq + 1}],
+            {ok, _, Acc2} = couch_btree:fold(Bt, Fun, Acc1, FoldOpts),
+            {ok, #acc{seq = LastSeq}} = replicate_batch(Acc2),
+            {ok, couch_db:count_changes_since(Db, LastSeq)}
+    end.
 
 
 calculate_start_seq(Acc) ->

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <co...@couchdb.apache.org>'].