Return-Path: Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: (qmail 65051 invoked from network); 24 Feb 2010 04:17:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 24 Feb 2010 04:17:16 -0000 Received: (qmail 25812 invoked by uid 500); 24 Feb 2010 04:17:15 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 25702 invoked by uid 500); 24 Feb 2010 04:17:15 -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 25693 invoked by uid 99); 24 Feb 2010 04:17:15 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Feb 2010 04:17:15 +0000 X-ASF-Spam-Status: No, hits=-1998.8 required=10.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, 24 Feb 2010 04:17:08 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id EBB4423889B8; Wed, 24 Feb 2010 04:16:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r915665 - in /couchdb/branches/0.11.x: share/www/script/test/replication.js src/couchdb/couch_httpd_misc_handlers.erl src/couchdb/couch_rep.erl Date: Wed, 24 Feb 2010 04:16:47 -0000 To: commits@couchdb.apache.org From: jan@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100224041647.EBB4423889B8@eris.apache.org> Author: jan Date: Wed Feb 24 04:16:47 2010 New Revision: 915665 URL: http://svn.apache.org/viewvc?rev=915665&view=rev Log: Allow replication to be cancelled. Closes COUCHDB-664. Patch by Robert Newson. Modified: couchdb/branches/0.11.x/share/www/script/test/replication.js couchdb/branches/0.11.x/src/couchdb/couch_httpd_misc_handlers.erl couchdb/branches/0.11.x/src/couchdb/couch_rep.erl Modified: couchdb/branches/0.11.x/share/www/script/test/replication.js URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/share/www/script/test/replication.js?rev=915665&r1=915664&r2=915665&view=diff ============================================================================== --- couchdb/branches/0.11.x/share/www/script/test/replication.js (original) +++ couchdb/branches/0.11.x/share/www/script/test/replication.js Wed Feb 24 04:16:47 2010 @@ -302,7 +302,26 @@ TEquals("test_suite_db_b", dbB.info().db_name, "Target database should exist"); - + // continuous + var continuousResult = CouchDB.replicate(dbA.name, "test_suite_db_b", { + body: {"continuous": true} + }); + T(continuousResult.ok) + T(continuousResult._local_id) + + var cancelResult = CouchDB.replicate(dbA.name, "test_suite_db_b", { + body: {"cancel": true} + }); + T(cancelResult.ok) + T(continuousResult._local_id == cancelResult._local_id) + + try { + var cancelResult2 = CouchDB.replicate(dbA.name, "test_suite_db_b", { + body: {"cancel": true} + }); + } catch (e) { + T(e.error == "not_found") + } // test replication object option doc_ids var dbA = new CouchDB("test_suite_rep_docs_db_a", {"X-Couch-Full-Commit":"false"}); Modified: couchdb/branches/0.11.x/src/couchdb/couch_httpd_misc_handlers.erl URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/src/couchdb/couch_httpd_misc_handlers.erl?rev=915665&r1=915664&r2=915665&view=diff ============================================================================== --- couchdb/branches/0.11.x/src/couchdb/couch_httpd_misc_handlers.erl (original) +++ couchdb/branches/0.11.x/src/couchdb/couch_httpd_misc_handlers.erl Wed Feb 24 04:16:47 2010 @@ -90,10 +90,14 @@ try couch_rep:replicate(PostBody, Req#httpd.user_ctx) of {ok, {continuous, RepId}} -> send_json(Req, 202, {[{ok, true}, {<<"_local_id">>, RepId}]}); + {ok, {cancelled, RepId}} -> + send_json(Req, 200, {[{ok, true}, {<<"_local_id">>, RepId}]}); {ok, {JsonResults}} -> send_json(Req, {[{ok, true} | JsonResults]}); {error, {Type, Details}} -> send_json(Req, 500, {[{error, Type}, {reason, Details}]}); + {error, not_found} -> + send_json(Req, 404, {[{error, not_found}]}); {error, Reason} -> send_json(Req, 500, {[{error, Reason}]}) catch Modified: couchdb/branches/0.11.x/src/couchdb/couch_rep.erl URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/src/couchdb/couch_rep.erl?rev=915665&r1=915664&r2=915665&view=diff ============================================================================== --- couchdb/branches/0.11.x/src/couchdb/couch_rep.erl (original) +++ couchdb/branches/0.11.x/src/couchdb/couch_rep.erl Wed Feb 24 04:16:47 2010 @@ -68,13 +68,24 @@ [?MODULE] }, - Server = start_replication_server(Replicator), - - case proplists:get_value(<<"continuous">>, Props, false) of + case proplists:get_value(<<"cancel">>, Props, false) of true -> - {ok, {continuous, ?l2b(BaseId)}}; + case supervisor:terminate_child(couch_rep_sup, BaseId ++ Extension) of + {error, not_found} -> + {error, not_found}; + ok -> + ok = supervisor:delete_child(couch_rep_sup, BaseId ++ Extension), + {ok, {cancelled, ?l2b(BaseId)}} + end; false -> - get_result(Server, PostBody, UserCtx) + Server = start_replication_server(Replicator), + + case proplists:get_value(<<"continuous">>, Props, false) of + true -> + {ok, {continuous, ?l2b(BaseId)}}; + false -> + get_result(Server, PostBody, UserCtx) + end end. checkpoint(Server) ->