continue jobs that aren't _replicator docs

This is a cherry-pick of:

https://github.com/cloudant/couch_replicator/commit/ff1ab1b840019601c3e3e04a1d931db6f2ccd2d1


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

Branch: refs/heads/2707-merge-couch_replicator-fixes-from-cloudant-fork
Commit: 9259784d589bd27f54ae388355e0e78e5be413ac
Parents: 5084604
Author: Robert Newson <rnew...@apache.org>
Authored: Thu May 21 14:08:42 2015 +0100
Committer: Mike Wallace <mikewall...@apache.org>
Committed: Tue Jun 2 18:22:11 2015 +0100

----------------------------------------------------------------------
 src/couch_replicator.erl         |  8 ++++----
 src/couch_replicator_manager.erl | 12 +++++++-----
 2 files changed, 11 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/9259784d/src/couch_replicator.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator.erl b/src/couch_replicator.erl
index 3a744cd..f8a3e65 100644
--- a/src/couch_replicator.erl
+++ b/src/couch_replicator.erl
@@ -475,9 +475,9 @@ handle_cast({db_compacted, DbName},
     {noreply, State#rep_state{target = NewTarget}};
 
 handle_cast(checkpoint, State) ->
-    #rep_state{rep_details = #rep{id = RepId} = Rep} = State,
-    case couch_replicator_manager:owner(RepId) of
-    Owner when Owner == node() ->
+    #rep_state{rep_details = #rep{} = Rep} = State,
+    case couch_replicator_manager:continue(Rep) of
+    {true, _} ->
         case do_checkpoint(State) of
         {ok, NewState} ->
             couch_stats:increment_counter([couch_replicator, checkpoints, 
success]),
@@ -486,7 +486,7 @@ handle_cast(checkpoint, State) ->
             couch_stats:increment_counter([couch_replicator, checkpoints, 
failure]),
             {stop, Error, State}
         end;
-    Owner ->
+    {false, Owner} ->
         couch_replicator_manager:replication_usurped(Rep, Owner),
         {stop, shutdown, State}
     end;

http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/9259784d/src/couch_replicator_manager.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator_manager.erl b/src/couch_replicator_manager.erl
index 39e06b3..0961889 100644
--- a/src/couch_replicator_manager.erl
+++ b/src/couch_replicator_manager.erl
@@ -17,7 +17,7 @@
 
 % public API
 -export([replication_started/1, replication_completed/2, replication_error/2]).
--export([owner/1, replication_usurped/2]).
+-export([continue/1, replication_usurped/2]).
 
 -export([before_doc_update/2, after_doc_read/2]).
 
@@ -131,9 +131,11 @@ replication_error(#rep{id = {BaseId, _} = RepId}, Error) ->
         ok = gen_server:call(?MODULE, {rep_error, RepId, Error}, infinity)
     end.
 
-
-owner(RepId) ->
-    gen_server:call(?MODULE, {owner, RepId}).
+continue(#rep{doc_id = null}) ->
+    {true, no_owner};
+continue(#rep{id = RepId}) ->
+    Owner = gen_server:call(?MODULE, {owner, RepId}),
+    {node() == Owner, Owner}.
 
 
 handle_config_change("replicator", "db", _, _, S) ->
@@ -178,7 +180,7 @@ init(_) ->
 handle_call({owner, RepId}, _From, State) ->
     case rep_state(RepId) of
     nil ->
-        false;
+        {reply, nonode, State};
     #rep_state{dbname = DbName, rep = #rep{doc_id = DocId}} ->
         {reply, owner(DbName, DocId, State#state.live), State}
     end;

Reply via email to