You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2010/02/24 05:15:58 UTC

svn commit: r915664 - in /couchdb/trunk: share/www/script/test/replication.js src/couchdb/couch_httpd_misc_handlers.erl src/couchdb/couch_rep.erl

Author: jan
Date: Wed Feb 24 04:15:58 2010
New Revision: 915664

URL: http://svn.apache.org/viewvc?rev=915664&view=rev
Log:
Allow replication to be cancelled. Closes COUCHDB-664. Patch by Robert Newson.

Modified:
    couchdb/trunk/share/www/script/test/replication.js
    couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl
    couchdb/trunk/src/couchdb/couch_rep.erl

Modified: couchdb/trunk/share/www/script/test/replication.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/replication.js?rev=915664&r1=915663&r2=915664&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/replication.js (original)
+++ couchdb/trunk/share/www/script/test/replication.js Wed Feb 24 04:15:58 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/trunk/src/couchdb/couch_httpd_misc_handlers.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl?rev=915664&r1=915663&r2=915664&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl Wed Feb 24 04:15:58 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/trunk/src/couchdb/couch_rep.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_rep.erl?rev=915664&r1=915663&r2=915664&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_rep.erl (original)
+++ couchdb/trunk/src/couchdb/couch_rep.erl Wed Feb 24 04:15:58 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) ->