You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by mi...@apache.org on 2015/06/02 19:29:13 UTC

[06/13] couch-replicator commit: updated refs/heads/2707-merge-couch_replicator-fixes-from-cloudant-fork to 367562b

Return owner to improve logging output

This is a cherry-pick of:

https://github.com/cloudant/couch_replicator/commit/3287da36a24b5d061a64cc93814f2f4580fdd4f9

Conflicts:
	src/couch_replicator_manager.erl


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

Branch: refs/heads/2707-merge-couch_replicator-fixes-from-cloudant-fork
Commit: 5dc5c415a570d90918814eaa743747faf449d71d
Parents: dab36db
Author: Robert Newson <rn...@apache.org>
Authored: Fri May 15 16:30:34 2015 +0100
Committer: Mike Wallace <mi...@apache.org>
Committed: Tue Jun 2 18:16:53 2015 +0100

----------------------------------------------------------------------
 src/couch_replicator_manager.erl | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/5dc5c415/src/couch_replicator_manager.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator_manager.erl b/src/couch_replicator_manager.erl
index 9cfda3f..a203b9f 100644
--- a/src/couch_replicator_manager.erl
+++ b/src/couch_replicator_manager.erl
@@ -17,6 +17,7 @@
 
 % public API
 -export([replication_started/1, replication_completed/2, replication_error/2]).
+-export([owner/1]).
 
 -export([before_doc_update/2, after_doc_read/2]).
 
@@ -120,6 +121,10 @@ replication_error(#rep{id = {BaseId, _} = RepId}, Error) ->
     end.
 
 
+owner(RepId) ->
+    gen_server:call(?MODULE, {owner, RepId}).
+
+
 handle_config_change("replicator", "db", _, _, S) ->
     ok = gen_server:call(S, rep_db_changed),
     remove_handler;
@@ -159,6 +164,13 @@ init(_) ->
         live = Live
     }}.
 
+handle_call({owner, RepId}, _From, State) ->
+    case rep_state(RepId) of
+    nil ->
+        false;
+    #rep_state{dbname = DbName, rep = #rep{doc_id = DocId}} ->
+        {reply, owner(DbName, DocId, State#state.live), State}
+    end;
 
 handle_call({rep_db_update, DbName, {ChangeProps} = Change}, _From, State) ->
     NewState = try
@@ -392,9 +404,11 @@ process_update(State, DbName, {Change}) ->
     {_, true} ->
         rep_doc_deleted(DbName, DocId),
         State;
-    {false, false} ->
+    {Owner, false} when Owner /= node() ->
+        couch_log:notice("Not starting '~s' as owner is ~s.", [DocId, Owner]),
         State;
-    {true, false} ->
+    {_Owner, false} ->
+        couch_log:notice("Maybe starting '~s' as I'm the owner", [DocId]),
         case get_json_value(<<"_replication_state">>, RepProps) of
         undefined ->
             maybe_start_replication(State, DbName, DocId, JsonRepDoc);
@@ -416,9 +430,7 @@ process_update(State, DbName, {Change}) ->
 owner(<<"shards/", _/binary>> = DbName, DocId, Live) ->
     Nodes = lists:sort([N || #shard{node=N} <- mem3:shards(mem3:dbname(DbName), DocId),
 			     lists:member(N, Live)]),
-    node() =:= hd(mem3_util:rotate_list({DbName, DocId}, Nodes));
-owner(_DbName, _DocId, _Live) ->
-    true.
+    hd(mem3_util:rotate_list({DbName, DocId}, Nodes)).
 
 rep_db_update_error(Error, DbName, DocId) ->
     case Error of