couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r766883 - /couchdb/trunk/src/couchdb/couch_db_updater.erl
Date Mon, 20 Apr 2009 21:34:48 GMT
Author: damien
Date: Mon Apr 20 21:34:46 2009
New Revision: 766883

URL: http://svn.apache.org/viewvc?rev=766883&view=rev
Log:
Fix for process leaks with retrying compactions.

Modified:
    couchdb/trunk/src/couchdb/couch_db_updater.erl

Modified: couchdb/trunk/src/couchdb/couch_db_updater.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_db_updater.erl?rev=766883&r1=766882&r2=766883&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_db_updater.erl (original)
+++ couchdb/trunk/src/couchdb/couch_db_updater.erl Mon Apr 20 21:34:46 2009
@@ -157,7 +157,8 @@
     {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 @@
                 [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 @@
         ?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 @@
         }.
 
 
+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 @@
         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).
     



Mime
View raw message