You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2014/08/06 20:18:10 UTC

[20/27] couch-replicator commit: updated refs/heads/windsor-merge to 75e5ba1

Fallback to using source seq for Apache CouchDB

If the update_seq is a number we assume that the source server is Apache
CouchDB so we fall back to comparing the current update_seq against the
update_seq value in the database info blob.

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/777da3d1
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/tree/777da3d1
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/diff/777da3d1

Branch: refs/heads/windsor-merge
Commit: 777da3d1ed2d9ded240016273f3669c0660eaae9
Parents: a18aa43
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Dec 11 11:58:04 2013 -0600
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 15:18:00 2014 +0100

----------------------------------------------------------------------
 src/couch_replicator_api_wrap.erl | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/777da3d1/src/couch_replicator_api_wrap.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator_api_wrap.erl b/src/couch_replicator_api_wrap.erl
index 3b2e1de..fd8edc4 100644
--- a/src/couch_replicator_api_wrap.erl
+++ b/src/couch_replicator_api_wrap.erl
@@ -125,15 +125,24 @@ get_db_info(#db{name = DbName, user_ctx = UserCtx}) ->
     {ok, [{couch_util:to_binary(K), V} || {K, V} <- Info]}.
 
 
+get_pending_count(#httpdb{} = Db, Seq) when is_number(Seq) ->
+    % Source looks like Apache CouchDB and not Cloudant so we fall
+    % back to using update sequence differences.
+    send_req(Db, [], fun(200, _, {Props}) ->
+        case get_value(<<"update_seq">>, Props) of
+            UpdateSeq when is_number(UpdateSeq) ->
+                {ok, UpdateSeq - Seq};
+            _ ->
+                {ok, null}
+        end
+    end);
 get_pending_count(#httpdb{} = Db, Seq) ->
-    send_req(
-        Db,
-        [{path, "_changes"}, {qs, [{"since", Seq}, {"limit", "0"}]}],
-        fun(200, _, {Props}) ->
-            {ok, couch_util:get_value(<<"pending">>, Props, null)}
-        end);
-get_pending_count(#db{name=DbName, user_ctx = UserCtx}, Seq) ->
-    {ok, Db} = couch_db:open(DbName, [{user_ctx, UserCtx}]),
+    Options = [{path, "_changes"}, {qs, [{"since", Seq}, {"limit", "0"}]}],
+    send_req(Db, Options, fun(200, _, {Props}) ->
+        {ok, couch_util:get_value(<<"pending">>, Props, null)}
+    end);
+get_pending_count(#db{name=DbName}=Db, Seq) when is_number(Seq) ->
+    {ok, Db} = couch_db:open(DbName, [{user_ctx, Db#db.user_ctx}]),
     Pending = couch_db:count_changes_since(Db, Seq),
     couch_db:close(Db),
     {ok, Pending}.