Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 40CC918BDC for ; Tue, 2 Jun 2015 17:29:09 +0000 (UTC) Received: (qmail 53188 invoked by uid 500); 2 Jun 2015 17:29:08 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 53078 invoked by uid 500); 2 Jun 2015 17:29:08 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 52844 invoked by uid 99); 2 Jun 2015 17:29:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Jun 2015 17:29:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 81589E0281; Tue, 2 Jun 2015 17:29:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mikewallace@apache.org To: commits@couchdb.apache.org Date: Tue, 02 Jun 2015 17:29:15 -0000 Message-Id: <0db41c845d964840871230f397316d11@git.apache.org> In-Reply-To: <2cbe77137a07480b9e46c3e25c325398@git.apache.org> References: <2cbe77137a07480b9e46c3e25c325398@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [08/13] couch-replicator commit: updated refs/heads/2707-merge-couch_replicator-fixes-from-cloudant-fork to 367562b Cleanly stop replication at checkpoint time if no longer owner This is a cherry-pick of: https://github.com/cloudant/couch_replicator/commit/e5ef7c8a0ee2566b9cd4c02397ee94883d015fa0 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/44e755e5 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/tree/44e755e5 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/diff/44e755e5 Branch: refs/heads/2707-merge-couch_replicator-fixes-from-cloudant-fork Commit: 44e755e5108262877c2aad48f3846e7139c877b7 Parents: 3675764 Author: Robert Newson Authored: Fri May 15 16:31:24 2015 +0100 Committer: Mike Wallace Committed: Tue Jun 2 18:19:09 2015 +0100 ---------------------------------------------------------------------- src/couch_replicator.erl | 21 ++++++++++++++------- src/couch_replicator_manager.erl | 13 ++++++++++++- 2 files changed, 26 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/44e755e5/src/couch_replicator.erl ---------------------------------------------------------------------- diff --git a/src/couch_replicator.erl b/src/couch_replicator.erl index 6e86a8f..3a744cd 100644 --- a/src/couch_replicator.erl +++ b/src/couch_replicator.erl @@ -475,13 +475,20 @@ handle_cast({db_compacted, DbName}, {noreply, State#rep_state{target = NewTarget}}; handle_cast(checkpoint, State) -> - case do_checkpoint(State) of - {ok, NewState} -> - couch_stats:increment_counter([couch_replicator, checkpoints, success]), - {noreply, NewState#rep_state{timer = start_timer(State)}}; - Error -> - couch_stats:increment_counter([couch_replicator, checkpoints, failure]), - {stop, Error, State} + #rep_state{rep_details = #rep{id = RepId} = Rep} = State, + case couch_replicator_manager:owner(RepId) of + Owner when Owner == node() -> + case do_checkpoint(State) of + {ok, NewState} -> + couch_stats:increment_counter([couch_replicator, checkpoints, success]), + {noreply, NewState#rep_state{timer = start_timer(State)}}; + Error -> + couch_stats:increment_counter([couch_replicator, checkpoints, failure]), + {stop, Error, State} + end; + Owner -> + couch_replicator_manager:replication_usurped(Rep, Owner), + {stop, shutdown, State} end; handle_cast({report_seq, Seq}, http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/44e755e5/src/couch_replicator_manager.erl ---------------------------------------------------------------------- diff --git a/src/couch_replicator_manager.erl b/src/couch_replicator_manager.erl index 6410a85..39e06b3 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]). +-export([owner/1, replication_usurped/2]). -export([before_doc_update/2, after_doc_read/2]). @@ -108,6 +108,17 @@ replication_completed(#rep{id = RepId}, Stats) -> end. +replication_usurped(#rep{id = RepId}, By) -> + case rep_state(RepId) of + nil -> + ok; + #rep_state{rep = #rep{doc_id = DocId}} -> + ok = gen_server:call(?MODULE, {rep_complete, RepId}, infinity), + couch_log:notice("Replication `~s` usurped by ~s (triggered by document `~s`)", + [pp_rep_id(RepId), By, DocId]) + end. + + replication_error(#rep{id = {BaseId, _} = RepId}, Error) -> case rep_state(RepId) of nil ->