From commits-return-6350-apmail-couchdb-commits-archive=couchdb.apache.org@couchdb.apache.org Wed May 11 11:49:49 2011 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 196544EDE for ; Wed, 11 May 2011 11:49:49 +0000 (UTC) Received: (qmail 48441 invoked by uid 500); 11 May 2011 11:49:49 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 48400 invoked by uid 500); 11 May 2011 11:49:49 -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 48393 invoked by uid 99); 11 May 2011 11:49:48 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 May 2011 11:49:48 +0000 X-ASF-Spam-Status: No, hits=-1996.4 required=5.0 tests=ALL_TRUSTED,FS_REPLICA X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 May 2011 11:49:48 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id CD87523889E7; Wed, 11 May 2011 11:49:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1101844 - /couchdb/trunk/src/couchdb/couch_replicator.erl Date: Wed, 11 May 2011 11:49:27 -0000 To: commits@couchdb.apache.org From: fdmanana@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110511114927.CD87523889E7@eris.apache.org> Author: fdmanana Date: Wed May 11 11:49:27 2011 New Revision: 1101844 URL: http://svn.apache.org/viewvc?rev=1101844&view=rev Log: Replicator: better error handling with remote _changes connection Once the connection to remote _changes dies, retry it with the last source sequence number we got instead of using the initial one. Modified: couchdb/trunk/src/couchdb/couch_replicator.erl Modified: couchdb/trunk/src/couchdb/couch_replicator.erl URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_replicator.erl?rev=1101844&r1=1101843&r2=1101844&view=diff ============================================================================== --- couchdb/trunk/src/couchdb/couch_replicator.erl (original) +++ couchdb/trunk/src/couchdb/couch_replicator.erl Wed May 11 11:49:27 2011 @@ -578,15 +578,28 @@ fold_replication_logs([Db | Rest] = Dbs, end. -spawn_changes_reader(StartSeq, Source, ChangesQueue, Options) -> - spawn_link( - fun()-> - couch_api_wrap:changes_since(Source, all_docs, StartSeq, - fun(DocInfo) -> - ok = couch_work_queue:queue(ChangesQueue, DocInfo) - end, Options), - couch_work_queue:close(ChangesQueue) - end). +spawn_changes_reader(StartSeq, #httpdb{} = Db, ChangesQueue, Options) -> + spawn_link(fun() -> + put(last_seq, StartSeq), + read_changes(StartSeq, Db#httpdb{retries = 0}, ChangesQueue, Options) + end); +spawn_changes_reader(StartSeq, Db, ChangesQueue, Options) -> + spawn_link(fun() -> read_changes(StartSeq, Db, ChangesQueue, Options) end). + +read_changes(StartSeq, Db, ChangesQueue, Options) -> + try + couch_api_wrap:changes_since(Db, all_docs, StartSeq, + fun(#doc_info{high_seq = Seq} = DocInfo) -> + ok = couch_work_queue:queue(ChangesQueue, DocInfo), + put(last_seq, Seq) + end, Options), + couch_work_queue:close(ChangesQueue) + catch exit:{http_request_failed, _, _, _} -> + Url = couch_util:url_strip_password(couch_api_wrap_httpc:full_url(Db, [])), + ?LOG_INFO("Retrying _changes request to source database ~s with since=~p", + [Url, get(last_seq)]), + read_changes(get(last_seq), Db, ChangesQueue, Options) + end. checkpoint_interval(_State) ->