summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien F. Katz <damien@apache.org>2009-04-20 21:34:46 +0000
committerDamien F. Katz <damien@apache.org>2009-04-20 21:34:46 +0000
commit40ff96300b7eb8aa1751d8377b3960157bf57673 (patch)
treeec18134aa91333e00a0ecdad59c8086fd80eedeb
parent8c546e269e8a57ae646b6a945802bfd7358a1813 (diff)
Fix for process leaks with retrying compactions.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@766883 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/couchdb/couch_db_updater.erl21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/couchdb/couch_db_updater.erl b/src/couchdb/couch_db_updater.erl
index ba9be1e4..1267ffa4 100644
--- a/src/couchdb/couch_db_updater.erl
+++ b/src/couchdb/couch_db_updater.erl
@@ -157,7 +157,8 @@ handle_cast({compact_done, CompactFilepath}, #db{filepath=Filepath}=Db) ->
{ok, NewFd} = couch_file:open(CompactFilepath),
{ok, NewHeader} = couch_file:read_header(NewFd, ?HEADER_SIG),
#db{update_seq=NewSeq} = NewDb =
- init_db(Db#db.name, CompactFilepath, NewFd, NewHeader),
+ init_db(Db#db.name, Filepath, NewFd, NewHeader),
+ unlink(NewFd),
case Db#db.update_seq == NewSeq of
true ->
% suck up all the local docs into memory and write them to the new db
@@ -172,10 +173,7 @@ handle_cast({compact_done, CompactFilepath}, #db{filepath=Filepath}=Db) ->
[Filepath, CompactFilepath]),
file:delete(Filepath),
ok = file:rename(CompactFilepath, Filepath),
-
- couch_stream:close(Db#db.summary_stream),
- couch_ref_counter:drop(Db#db.fd_ref_counter),
-
+ close_db(Db),
ok = gen_server:call(Db#db.main_pid, {db_updated, NewDb2}),
?LOG_INFO("Compaction for db \"~s\" completed.", [Db#db.name]),
{noreply, NewDb2#db{compactor_pid=nil}};
@@ -183,7 +181,7 @@ handle_cast({compact_done, CompactFilepath}, #db{filepath=Filepath}=Db) ->
?LOG_INFO("Compaction file still behind main file "
"(update seq=~p. compact update seq=~p). Retrying.",
[Db#db.update_seq, NewSeq]),
- couch_file:close(NewFd),
+ close_db(NewDb),
Pid = spawn_link(fun() -> start_copy_compact(Db) end),
Db2 = Db#db{compactor_pid=Pid},
{noreply, Db2}
@@ -303,6 +301,11 @@ init_db(DbName, Filepath, Fd, Header0) ->
}.
+close_db(#db{ fd_ref_counter = RefCntr, summary_stream = SummaryStream}) ->
+ couch_stream:close(SummaryStream),
+ couch_ref_counter:drop(RefCntr).
+
+
refresh_validate_doc_funs(Db) ->
{ok, DesignDocs} = get_design_docs(Db),
ProcessDocFuns = lists:flatmap(
@@ -644,7 +647,9 @@ start_copy_compact(#db{name=Name,filepath=Filepath}=Db) ->
ok = couch_file:write_header(Fd, ?HEADER_SIG, Header=#db_header{})
end,
NewDb = init_db(Name, CompactFile, Fd, Header),
- _NewDb2 = copy_compact(Db, NewDb, Retry),
+ unlink(Fd),
+ NewDb2 = copy_compact(Db, NewDb, Retry),
- gen_server:cast(Db#db.update_pid, {compact_done, CompactFile}).
+ gen_server:cast(Db#db.update_pid, {compact_done, CompactFile}),
+ close_db(NewDb2).