couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
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 GMT
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) ->



Mime
View raw message