couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikewall...@apache.org
Subject [03/11] couch-replicator commit: updated refs/heads/2707-merge-couch_replicator-fixes-from-cloudant-fork to 80708a9
Date Fri, 05 Jun 2015 16:42:59 GMT
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/89363ae5
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/tree/89363ae5
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/diff/89363ae5

Branch: refs/heads/2707-merge-couch_replicator-fixes-from-cloudant-fork
Commit: 89363ae52e06f8f7e5a82d2ebe106dc41622ce01
Parents: 8d69019
Author: Robert Newson <rnewson@apache.org>
Authored: Fri May 15 16:30:34 2015 +0100
Committer: Mike Wallace <mikewallace@apache.org>
Committed: Fri Jun 5 17:20:20 2015 +0100

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


http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/89363ae5/src/couch_replicator_manager.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator_manager.erl b/src/couch_replicator_manager.erl
index 5369ad5..4f32ede 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,9 @@ 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));
+    hd(mem3_util:rotate_list({DbName, DocId}, Nodes));
 owner(_DbName, _DocId, _Live) ->
-    true.
+    node().
 
 rep_db_update_error(Error, DbName, DocId) ->
     case Error of


Mime
View raw message