You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by fd...@apache.org on 2010/07/08 21:31:44 UTC

svn commit: r961897 - in /couchdb/branches/1.0.x: share/Makefile.am share/www/script/couch_tests.js share/www/script/test/view_compaction.js src/couchdb/couch_view_group.erl

Author: fdmanana
Date: Thu Jul  8 19:31:43 2010
New Revision: 961897

URL: http://svn.apache.org/viewvc?rev=961897&view=rev
Log:
Merge revision 961893 from trunk:

Fix deletion of view files after compaction.
Also added test for view compaction.

Thanks Adam for reporting the issue.



Added:
    couchdb/branches/1.0.x/share/www/script/test/view_compaction.js
Modified:
    couchdb/branches/1.0.x/share/Makefile.am
    couchdb/branches/1.0.x/share/www/script/couch_tests.js
    couchdb/branches/1.0.x/src/couchdb/couch_view_group.erl

Modified: couchdb/branches/1.0.x/share/Makefile.am
URL: http://svn.apache.org/viewvc/couchdb/branches/1.0.x/share/Makefile.am?rev=961897&r1=961896&r2=961897&view=diff
==============================================================================
--- couchdb/branches/1.0.x/share/Makefile.am (original)
+++ couchdb/branches/1.0.x/share/Makefile.am Thu Jul  8 19:31:43 2010
@@ -162,6 +162,7 @@ nobase_dist_localdata_DATA = \
     www/script/test/view_collation.js \
     www/script/test/view_collation_raw.js \
     www/script/test/view_conflicts.js \
+    www/script/test/view_compaction.js \
     www/script/test/view_errors.js \
     www/script/test/view_include_docs.js \
     www/script/test/view_multi_key_all_docs.js \

Modified: couchdb/branches/1.0.x/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/couchdb/branches/1.0.x/share/www/script/couch_tests.js?rev=961897&r1=961896&r2=961897&view=diff
==============================================================================
--- couchdb/branches/1.0.x/share/www/script/couch_tests.js [utf-8] (original)
+++ couchdb/branches/1.0.x/share/www/script/couch_tests.js [utf-8] Thu Jul  8 19:31:43 2010
@@ -85,6 +85,7 @@ loadTest("uuids.js");
 loadTest("view_collation.js");
 loadTest("view_collation_raw.js");
 loadTest("view_conflicts.js");
+loadTest("view_compaction.js");
 loadTest("view_errors.js");
 loadTest("view_include_docs.js");
 loadTest("view_multi_key_all_docs.js");

Added: couchdb/branches/1.0.x/share/www/script/test/view_compaction.js
URL: http://svn.apache.org/viewvc/couchdb/branches/1.0.x/share/www/script/test/view_compaction.js?rev=961897&view=auto
==============================================================================
--- couchdb/branches/1.0.x/share/www/script/test/view_compaction.js (added)
+++ couchdb/branches/1.0.x/share/www/script/test/view_compaction.js Thu Jul  8 19:31:43 2010
@@ -0,0 +1,102 @@
+// 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.
+
+couchTests.view_compaction = function(debug) {
+
+  if (debug) debugger;
+
+  var db = new CouchDB("test_suite_db", {"X-Couch-Full-Commit": "true"});
+
+  db.deleteDb();
+  db.createDb();
+
+  var ddoc = {
+    _id: "_design/foo",
+    language: "javascript",
+    views: {
+      view1: {
+        map: "function(doc) { emit(doc._id, doc.value) }"
+      },
+      view2: {
+        map: "function(doc) { emit(doc._id, doc.value); }",
+        reduce: "function(keys, values, rereduce) { return sum(values); }"
+      }
+    }
+  };
+  T(db.save(ddoc).ok);
+
+  var docs = makeDocs(0, 1000);
+  db.bulkSave(docs);
+
+  var resp = db.view('foo/view1', {});
+  T(resp.rows.length === 1000);
+
+  resp = db.view('foo/view2', {});
+  T(resp.rows.length === 1);
+
+  resp = db.designInfo("_design/foo");
+  T(resp.view_index.update_seq === 1001);
+
+
+  // update docs
+  for (var i = 0; i < docs.length; i++) {
+    docs[i].integer = docs[i].integer + 1;
+  }
+  db.bulkSave(docs);
+
+
+  resp = db.view('foo/view1', {});
+  T(resp.rows.length === 1000);
+
+  resp = db.view('foo/view2', {});
+  T(resp.rows.length === 1);
+
+  resp = db.designInfo("_design/foo");
+  T(resp.view_index.update_seq === 2001);
+
+
+  // update docs again...
+  for (var i = 0; i < docs.length; i++) {
+    docs[i].integer = docs[i].integer + 2;
+  }
+  db.bulkSave(docs);
+
+
+  resp = db.view('foo/view1', {});
+  T(resp.rows.length === 1000);
+
+  resp = db.view('foo/view2', {});
+  T(resp.rows.length === 1);
+
+  resp = db.designInfo("_design/foo");
+  T(resp.view_index.update_seq === 3001);
+
+
+  // compact view group
+  var xhr = CouchDB.request("POST", "/" + db.name + "/_compact" + "/foo");
+  T(JSON.parse(xhr.responseText).ok === true);
+
+  resp = db.designInfo("_design/foo");
+  while (resp.view_index.compact_running === true) {
+    resp = db.designInfo("_design/foo");
+  }
+
+
+  resp = db.view('foo/view1', {});
+  T(resp.rows.length === 1000);
+
+  resp = db.view('foo/view2', {});
+  T(resp.rows.length === 1);
+
+  resp = db.designInfo("_design/foo");
+  T(resp.view_index.update_seq === 3001);
+};
\ No newline at end of file

Modified: couchdb/branches/1.0.x/src/couchdb/couch_view_group.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/1.0.x/src/couchdb/couch_view_group.erl?rev=961897&r1=961896&r2=961897&view=diff
==============================================================================
--- couchdb/branches/1.0.x/src/couchdb/couch_view_group.erl (original)
+++ couchdb/branches/1.0.x/src/couchdb/couch_view_group.erl Thu Jul  8 19:31:43 2010
@@ -186,7 +186,7 @@ handle_cast({compact_done, #group{curren
     ?LOG_INFO("View index compaction complete for ~s ~s", [DbName, GroupId]),
     FileName = index_file_name(RootDir, DbName, GroupSig),
     CompactName = index_file_name(compact, RootDir, DbName, GroupSig),
-    couch_file:delete(FileName),
+    ok = couch_file:delete(RootDir, FileName),
     ok = file:rename(CompactName, FileName),
 
     %% if an updater is running, kill it and start a new one
@@ -545,7 +545,7 @@ reset_file(Db, Fd, DbName, #group{sig=Si
     init_group(Db, Fd, reset_group(Group), nil).
 
 delete_index_file(RootDir, DbName, GroupSig) ->
-    couch_file:delete(index_file_name(RootDir, DbName, GroupSig)).
+    couch_file:delete(RootDir, index_file_name(RootDir, DbName, GroupSig)).
 
 init_group(Db, Fd, #group{views=Views}=Group, nil) ->
     init_group(Db, Fd, Group,