couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [32/50] git commit: Teach replicator to gracefully reconnect
Date Fri, 17 Jan 2014 22:07:06 GMT
Teach replicator to gracefully reconnect

This patch allows the replicator to recognize the "last_seq" field at
the end of a continuous _changes feed and reconnect to the feed using
that value.

BugzID: 17502


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

Branch: refs/heads/import
Commit: c1f3d72f523b3cb3cc34206ce9c9c157b9b88f34
Parents: 17671fa
Author: Adam Kocoloski <adam@cloudant.com>
Authored: Fri Feb 22 10:45:23 2013 -0500
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Wed Mar 20 06:02:40 2013 -0500

----------------------------------------------------------------------
 src/couch_replicator.erl          | 16 +++++++++++++++-
 src/couch_replicator_api_wrap.erl | 27 ++++++++++++++++-----------
 2 files changed, 31 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/c1f3d72f/src/couch_replicator.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator.erl b/src/couch_replicator.erl
index c72a398..e1ff15c 100644
--- a/src/couch_replicator.erl
+++ b/src/couch_replicator.erl
@@ -642,7 +642,21 @@ read_changes(StartSeq, Db, ChangesQueue, Options) ->
                 _ ->
                     ok = couch_work_queue:queue(ChangesQueue, DocInfo)
                 end,
-                put(last_seq, Seq)
+                put(last_seq, Seq);
+            ({last_seq, LS}) ->
+                case get_value(continuous, Options) of
+                true ->
+                    % LS should never be undefined, but it doesn't hurt to be
+                    % defensive inside the replicator.
+                    Seq = case LS of undefined -> get(last_seq); _ -> LS end,
+                    read_changes(Seq, Db, ChangesQueue, Options);
+                _ ->
+                    % This clause is unreachable today, but let's plan ahead
+                    % for the future where we checkpoint against last_seq
+                    % instead of the sequence of the last change.  The two can
+                    % differ substantially in the case of a restrictive filter.
+                    ok
+                end
             end, Options),
         couch_work_queue:close(ChangesQueue)
     catch exit:{http_request_failed, _, _, _} = Error ->

http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/c1f3d72f/src/couch_replicator_api_wrap.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator_api_wrap.erl b/src/couch_replicator_api_wrap.erl
index ecf3064..abdd548 100644
--- a/src/couch_replicator_api_wrap.erl
+++ b/src/couch_replicator_api_wrap.erl
@@ -692,17 +692,22 @@ parse_changes_line(object_start, UserFun) ->
     end.
 
 json_to_doc_info({Props}) ->
-    RevsInfo = lists:map(
-        fun({Change}) ->
-            Rev = couch_doc:parse_rev(get_value(<<"rev">>, Change)),
-            Del = couch_replicator_utils:is_deleted(Change),
-            #rev_info{rev=Rev, deleted=Del}
-        end, get_value(<<"changes">>, Props)),
-    #doc_info{
-        id = get_value(<<"id">>, Props),
-        high_seq = get_value(<<"seq">>, Props),
-        revs = RevsInfo
-    }.
+    case get_value(<<"changes">>, Props) of
+    undefined ->
+        {last_seq, get_value(<<"last_seq">>, Props)};
+    Changes ->
+        RevsInfo = lists:map(
+            fun({Change}) ->
+                Rev = couch_doc:parse_rev(get_value(<<"rev">>, Change)),
+                Del = couch_replicator_utils:is_deleted(Change),
+                #rev_info{rev=Rev, deleted=Del}
+            end, Changes),
+        #doc_info{
+            id = get_value(<<"id">>, Props),
+            high_seq = get_value(<<"seq">>, Props),
+            revs = RevsInfo
+        }
+    end.
 
 
 bulk_results_to_errors(Docs, {ok, Results}, interactive_edit) ->


Mime
View raw message