diff options
author | Filipe David Borba Manana <fdmanana@apache.org> | 2010-07-08 19:23:33 +0000 |
---|---|---|
committer | Filipe David Borba Manana <fdmanana@apache.org> | 2010-07-08 19:23:33 +0000 |
commit | f3442c25ae26369a516cf12b94f86cdec406c5b6 (patch) | |
tree | 496ead6461728e5b64047c0029f03e8dc8c0ad99 | |
parent | 5c55239750edc5540825ef0bbf83fccb1bed459f (diff) |
Fix deletion of view files after compaction.
Also added test for view compaction.
Thanks Adam for reporting the issue.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@961893 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | share/Makefile.am | 1 | ||||
-rw-r--r-- | share/www/script/couch_tests.js | 1 | ||||
-rw-r--r-- | share/www/script/test/view_compaction.js | 102 | ||||
-rw-r--r-- | src/couchdb/couch_view_group.erl | 4 |
4 files changed, 106 insertions, 2 deletions
diff --git a/share/Makefile.am b/share/Makefile.am index fc052de0..c85f683f 100644 --- a/share/Makefile.am +++ b/share/Makefile.am @@ -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 \ diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index dc283bba..c5257ea6 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -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"); diff --git a/share/www/script/test/view_compaction.js b/share/www/script/test/view_compaction.js new file mode 100644 index 00000000..318dfdb5 --- /dev/null +++ b/share/www/script/test/view_compaction.js @@ -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 diff --git a/src/couchdb/couch_view_group.erl b/src/couchdb/couch_view_group.erl index 8d3a3d86..f01befdf 100644 --- a/src/couchdb/couch_view_group.erl +++ b/src/couchdb/couch_view_group.erl @@ -186,7 +186,7 @@ handle_cast({compact_done, #group{current_seq=NewSeq} = NewGroup}, ?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=Sig,name=Name} = Group) -> 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, |