diff options
author | Nick Vatamaniuc <vatamane@apache.org> | 2017-05-22 11:36:53 -0400 |
---|---|---|
committer | Nick Vatamaniuc <nickva@users.noreply.github.com> | 2017-05-22 13:09:01 -0400 |
commit | a9ad3429e7c40c9b4ec387fdb84567e5a67f8099 (patch) | |
tree | 8c12a2c365bb5312e4f40f6f90993c3362512f11 | |
parent | eb011f308ccf7e15c2d211b29a78864e3306f914 (diff) | |
download | couchdb-a9ad3429e7c40c9b4ec387fdb84567e5a67f8099.tar.gz |
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.
-rw-r--r-- | src/mem3/src/mem3_rep.erl | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/mem3/src/mem3_rep.erl b/src/mem3/src/mem3_rep.erl index ad7ac55f5..db09d3658 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) -> |