couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kocol...@apache.org
Subject svn commit: r1060150 - in /couchdb/branches/1.1.x: share/Makefile.am share/www/script/couch_tests.js share/www/script/test/attachment_conflicts.js src/couchdb/couch_httpd_db.erl
Date Tue, 18 Jan 2011 00:44:52 GMT
Author: kocolosk
Date: Tue Jan 18 00:44:51 2011
New Revision: 1060150

URL: http://svn.apache.org/viewvc?rev=1060150&view=rev
Log:
Avoid bug in rev tree logic during attachment uploads

This is a workaround for a bug in couch_key_tree, described in
COUCHDB-902, which would cause uploads to fail with spurious conflicts.
A patch for the key tree itself will be landing on trunk.

Thanks Bob Dionne, Klaus Trainer.

Added:
    couchdb/branches/1.1.x/share/www/script/test/attachment_conflicts.js
Modified:
    couchdb/branches/1.1.x/share/Makefile.am
    couchdb/branches/1.1.x/share/www/script/couch_tests.js
    couchdb/branches/1.1.x/src/couchdb/couch_httpd_db.erl

Modified: couchdb/branches/1.1.x/share/Makefile.am
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/share/Makefile.am?rev=1060150&r1=1060149&r2=1060150&view=diff
==============================================================================
--- couchdb/branches/1.1.x/share/Makefile.am (original)
+++ couchdb/branches/1.1.x/share/Makefile.am Tue Jan 18 00:44:51 2011
@@ -114,6 +114,7 @@ nobase_dist_localdata_DATA = \
     www/script/test/all_docs.js \
     www/script/test/attachments.js \
     www/script/test/attachments_multipart.js \
+    www/script/test/attachment_conflicts.js \
     www/script/test/attachment_names.js \
     www/script/test/attachment_paths.js \
     www/script/test/attachment_ranges.js \

Modified: couchdb/branches/1.1.x/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/share/www/script/couch_tests.js?rev=1060150&r1=1060149&r2=1060150&view=diff
==============================================================================
--- couchdb/branches/1.1.x/share/www/script/couch_tests.js [utf-8] (original)
+++ couchdb/branches/1.1.x/share/www/script/couch_tests.js [utf-8] Tue Jan 18 00:44:51 2011
@@ -34,6 +34,7 @@ loadTest("basics.js");
 loadTest("all_docs.js");
 loadTest("attachments.js");
 loadTest("attachments_multipart.js");
+loadTest("attachment_conflicts.js");
 loadTest("attachment_names.js");
 loadTest("attachment_paths.js");
 loadTest("attachment_ranges.js");

Added: couchdb/branches/1.1.x/share/www/script/test/attachment_conflicts.js
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/share/www/script/test/attachment_conflicts.js?rev=1060150&view=auto
==============================================================================
--- couchdb/branches/1.1.x/share/www/script/test/attachment_conflicts.js (added)
+++ couchdb/branches/1.1.x/share/www/script/test/attachment_conflicts.js Tue Jan 18 00:44:51
2011
@@ -0,0 +1,56 @@
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+// Do some edit conflict detection tests for attachments.
+couchTests.attachment_conflicts = function(debug) {
+
+  var dbA = new CouchDB("test_suite_db_a", {"X-Couch-Full-Commit":"false"});
+  var dbB = new CouchDB("test_suite_db_b", {"X-Couch-Full-Commit":"false"});
+  dbA.deleteDb();
+  dbA.createDb();
+  dbB.deleteDb();
+  dbB.createDb();
+
+  if (debug) debugger;
+
+  T(dbA.save({"_id":"doc", "foo":"bar"}).ok);
+
+  // create conflict
+  T(CouchDB.replicate("test_suite_db_a", "test_suite_db_b").ok);
+
+  var doc = dbA.open("doc");
+  var rev11 = doc._rev;
+    T(dbA.save({"_id":"doc", "foo":"bar2","_rev":rev11}).ok);
+
+  doc = dbB.open("doc");
+  var rev12 = doc._rev;
+    T(dbB.save({"_id":"doc", "foo":"bar3","_rev":rev12}).ok);
+
+  T(CouchDB.replicate("test_suite_db_a", "test_suite_db_b").ok);
+
+  // the attachment
+  var bin_data = "JHAPDO*AU£PN ){(3u[d 93DQ9¡€])}    ææøo'∂ƒæ≤çæππ•¥∫¶®#†π¶®¥π€ª®˙π8np";
+
+  doc = dbB.open("doc");
+  var rev13 = doc._rev;
+
+  // test that we can can attach to conflicting documents
+  var xhr = CouchDB.request("PUT", "/test_suite_db_b/doc/attachment.txt", {
+    headers: {
+      "Content-Type": "text/plain;charset=utf-8",
+      "If-Match": rev13
+    },
+    body: bin_data
+  });
+  T(xhr.status == 201);
+
+};

Modified: couchdb/branches/1.1.x/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_httpd_db.erl?rev=1060150&r1=1060149&r2=1060150&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_httpd_db.erl Tue Jan 18 00:44:51 2011
@@ -1059,8 +1059,10 @@ db_attachment_req(#httpd{method=Method,m
             end
     end,
 
-    #doc{atts=Atts} = Doc,
+    #doc{atts=Atts, revs = {Pos, Revs}} = Doc,
     DocEdited = Doc#doc{
+        % prune revision list as a workaround for key tree bug (COUCHDB-902)
+        revs = {Pos, case Revs of [] -> []; [Hd|_] -> [Hd] end},
         atts = NewAtt ++ [A || A <- Atts, A#att.name /= FileName]
     },
     {ok, UpdatedRev} = couch_db:update_doc(Db, DocEdited, []),



Mime
View raw message