You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/01/17 23:07:07 UTC
[33/50] git commit: Scope entries to their replicator db
Scope entries to their replicator db
Add db name to the doc id to ensure they are unique.
BugzID: 177426
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/b0e99d4b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/tree/b0e99d4b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/diff/b0e99d4b
Branch: refs/heads/import
Commit: b0e99d4bc326631043274a747f0119b57a581f37
Parents: 1f99c24
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Feb 20 23:49:29 2013 -0600
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Mar 20 06:02:40 2013 -0500
----------------------------------------------------------------------
src/couch_replicator_manager.erl | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/b0e99d4b/src/couch_replicator_manager.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator_manager.erl b/src/couch_replicator_manager.erl
index 1cfaadd..b0a9257 100644
--- a/src/couch_replicator_manager.erl
+++ b/src/couch_replicator_manager.erl
@@ -317,10 +317,10 @@ process_update(State, DbName, {Change}) ->
DocId = get_value(<<"_id">>, RepProps),
case {mem3_util:owner(DbName, DocId), get_value(deleted, Change, false)} of
{false, _} ->
- replication_complete(DocId),
+ replication_complete(DbName, DocId),
State;
{true, true} ->
- rep_doc_deleted(DocId),
+ rep_doc_deleted(DbName, DocId),
State;
{true, false} ->
case get_value(<<"_replication_state">>, RepProps) of
@@ -329,10 +329,10 @@ process_update(State, DbName, {Change}) ->
<<"triggered">> ->
maybe_start_replication(State, DbName, DocId, JsonRepDoc);
<<"completed">> ->
- replication_complete(DocId),
+ replication_complete(DbName, DocId),
State;
<<"error">> ->
- case ets:lookup(?DOC_TO_REP, DocId) of
+ case ets:lookup(?DOC_TO_REP, {DbName, DocId}) of
[] ->
maybe_start_replication(State, DbName, DocId, JsonRepDoc);
_ ->
@@ -377,7 +377,7 @@ maybe_start_replication(State, DbName, DocId, RepDoc) ->
max_retries = State#state.max_retries
},
true = ets:insert(?REP_TO_STATE, {RepId, RepState}),
- true = ets:insert(?DOC_TO_REP, {DocId, RepId}),
+ true = ets:insert(?DOC_TO_REP, {{DbName, DocId}, RepId}),
twig:log(notice,"Attempting to start replication `~s` (document `~s`).",
[pp_rep_id(RepId), DocId]),
Pid = spawn_link(fun() -> start_replication(Rep, 0) end),
@@ -427,9 +427,9 @@ start_replication(Rep, Wait) ->
replication_error(Rep, Error)
end.
-replication_complete(DocId) ->
- case ets:lookup(?DOC_TO_REP, DocId) of
- [{DocId, {BaseId, Ext} = RepId}] ->
+replication_complete(DbName, DocId) ->
+ case ets:lookup(?DOC_TO_REP, {DbName, DocId}) of
+ [{{DbName, DocId}, {BaseId, Ext} = RepId}] ->
case rep_state(RepId) of
nil ->
% Prior to OTP R14B02, temporary child specs remain in
@@ -448,18 +448,18 @@ replication_complete(DocId) ->
#rep_state{} ->
ok
end,
- true = ets:delete(?DOC_TO_REP, DocId);
+ true = ets:delete(?DOC_TO_REP, {DbName, DocId});
_ ->
ok
end.
-rep_doc_deleted(DocId) ->
- case ets:lookup(?DOC_TO_REP, DocId) of
- [{DocId, RepId}] ->
+rep_doc_deleted(DbName, DocId) ->
+ case ets:lookup(?DOC_TO_REP, {DbName, DocId}) of
+ [{{DbName, DocId}, RepId}] ->
couch_replicator:cancel_replication(RepId),
true = ets:delete(?REP_TO_STATE, RepId),
- true = ets:delete(?DOC_TO_REP, DocId),
+ true = ets:delete(?DOC_TO_REP, {DbName, DocId}),
twig:log(notice, "Stopped replication `~s` because replication document `~s`"
" was deleted", [pp_rep_id(RepId), DocId]);
[] ->
@@ -477,12 +477,13 @@ replication_error(State, RepId, Error) ->
maybe_retry_replication(#rep_state{retries_left = 0} = RepState, Error, State) ->
#rep_state{
+ dbname = DbName,
rep = #rep{id = RepId, doc_id = DocId},
max_retries = MaxRetries
} = RepState,
couch_replicator:cancel_replication(RepId),
true = ets:delete(?REP_TO_STATE, RepId),
- true = ets:delete(?DOC_TO_REP, DocId),
+ true = ets:delete(?DOC_TO_REP, {DbName, DocId}),
twig:log(error, "Error in replication `~s` (triggered by document `~s`): ~s"
"~nReached maximum retry attempts (~p).",
[pp_rep_id(RepId), DocId, to_binary(error_reason(Error)), MaxRetries]),