You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ch...@apache.org on 2014/08/28 19:30:16 UTC
[16/50] [abbrv] couch-replicator commit: updated
refs/heads/1963-eunit-bigcouch to 3cf0b13
Rate limit the retrieval of pending changes
This limits the update of the changes_pending field to once every
`connection_timeout` milliseconds.
BugzId: 26015
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/commit/06cf6995
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/tree/06cf6995
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/diff/06cf6995
Branch: refs/heads/1963-eunit-bigcouch
Commit: 06cf69957b1bb0272cc4a0e679275bab8c7a16d1
Parents: f10dec7
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Dec 11 10:08:23 2013 -0600
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 15:17:38 2014 +0100
----------------------------------------------------------------------
src/couch_replicator.erl | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/06cf6995/src/couch_replicator.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator.erl b/src/couch_replicator.erl
index 8041283..82c1360 100644
--- a/src/couch_replicator.erl
+++ b/src/couch_replicator.erl
@@ -875,7 +875,28 @@ db_monitor(_HttpDb) ->
nil.
-get_pending_count(#rep_state{source = #httpdb{} = Db0}=St) ->
+get_pending_count(St) ->
+ Rep = St#rep_state.rep_details,
+ Timeout = get_value(connection_timeout, Rep#rep.options),
+ TimeoutMicro = Timeout * 1000,
+ case get(pending_count_state) of
+ {LastUpdate, PendingCount} ->
+ case timer:now_diff(os:timestamp(), LastUpdate) > TimeoutMicro of
+ true ->
+ NewPendingCount = get_pending_count_int(St),
+ put(pending_count_state, {os:timestamp(), NewPendingCount}),
+ NewPendingCount;
+ false ->
+ PendingCount
+ end;
+ undefined ->
+ NewPendingCount = get_pending_count_int(St),
+ put(pending_count_state, {os:timestamp(), NewPendingCount}),
+ NewPendingCount
+ end.
+
+
+get_pending_count_int(#rep_state{source = #httpdb{} = Db0}=St) ->
{_, Seq} = St#rep_state.highest_seq_done,
Db = Db0#httpdb{retries = 3},
case (catch couch_replicator_api_wrap:get_pending_count(Db, Seq)) of
@@ -884,7 +905,7 @@ get_pending_count(#rep_state{source = #httpdb{} = Db0}=St) ->
_ ->
null
end;
-get_pending_count(#rep_state{source = Db}=St) ->
+get_pending_count_int(#rep_state{source = Db}=St) ->
{_, Seq} = St#rep_state.highest_seq_done,
{ok, Pending} = couch_replicator_api_wrap:get_pending_count(Db, Seq),
Pending.