summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Kocoloski <kocolosk@apache.org>2011-01-12 04:55:16 +0000
committerAdam Kocoloski <kocolosk@apache.org>2011-01-12 04:55:16 +0000
commit43da5dcc08fd83b6255f14d7a97ea177018f07e6 (patch)
treed0debc36f5377664eafe55c81a83acf83f93b58b
parent2a3b0a8d47430053541a84a3eeacaaef505308b1 (diff)
Preserve purge metadata during compaction, thanks Mike Leddy
Closes COUCHDB-1021 git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.0.x@1057988 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--THANKS1
-rw-r--r--share/www/script/test/purge.js8
-rw-r--r--src/couchdb/couch_db_updater.erl14
3 files changed, 20 insertions, 3 deletions
diff --git a/THANKS b/THANKS
index 5f57b196..15072e2a 100644
--- a/THANKS
+++ b/THANKS
@@ -69,5 +69,6 @@ suggesting improvements or submitting changes. Some of these people are:
* Juuso Väänänen <juuso@vaananen.org>
* Benjamin Young <byoung@bigbluehat.com>
* Gabriel Farrell <gsf747@gmail.com>
+ * Mike Leddy <mike@loop.com.br>
For a list of authors see the `AUTHORS` file.
diff --git a/share/www/script/test/purge.js b/share/www/script/test/purge.js
index af72ea4f..f8f45138 100644
--- a/share/www/script/test/purge.js
+++ b/share/www/script/test/purge.js
@@ -76,6 +76,14 @@ couchTests.purge = function(debug) {
}
T(db.view("test/single_doc").total_rows == 0);
+ // purge sequences are preserved after compaction (COUCHDB-1021)
+ T(db.compact().ok);
+ T(db.last_req.status == 202);
+ // compaction isn't instantaneous, loop until done
+ while (db.info().compact_running) {};
+ var compactInfo = db.info();
+ T(compactInfo.purge_seq == newInfo.purge_seq);
+
// purge documents twice in a row without loading views
// (causes full view rebuilds)
diff --git a/src/couchdb/couch_db_updater.erl b/src/couchdb/couch_db_updater.erl
index eb1a3edc..e660800d 100644
--- a/src/couchdb/couch_db_updater.erl
+++ b/src/couchdb/couch_db_updater.erl
@@ -847,7 +847,7 @@ copy_compact(Db, NewDb0, Retry) ->
commit_data(NewDb4#db{update_seq=Db#db.update_seq}).
-start_copy_compact(#db{name=Name,filepath=Filepath}=Db) ->
+start_copy_compact(#db{name=Name,filepath=Filepath,header=#db_header{purge_seq=PurgeSeq}}=Db) ->
CompactFile = Filepath ++ ".compact",
?LOG_DEBUG("Compaction process spawned for db \"~s\"", [Name]),
case couch_file:open(CompactFile) of
@@ -867,8 +867,16 @@ start_copy_compact(#db{name=Name,filepath=Filepath}=Db) ->
ok = couch_file:write_header(Fd, Header=#db_header{})
end,
NewDb = init_db(Name, CompactFile, Fd, Header),
+ NewDb2 = if PurgeSeq > 0 ->
+ {ok, PurgedIdsRevs} = couch_db:get_last_purged(Db),
+ {ok, Pointer} = couch_file:append_term(Fd, PurgedIdsRevs),
+ NewDb#db{header=Header#db_header{purge_seq=PurgeSeq, purged_docs=Pointer}};
+ true ->
+ NewDb
+ end,
unlink(Fd),
- NewDb2 = copy_compact(Db, NewDb, Retry),
- close_db(NewDb2),
+
+ NewDb3 = copy_compact(Db, NewDb2, Retry),
+ close_db(NewDb3),
gen_server:cast(Db#db.update_pid, {compact_done, CompactFile}).