couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r957303 - in /couchdb/trunk/src/couchdb: couch_db_updater.erl couch_file.erl couch_server.erl couch_view.erl couch_view_group.erl
Date Wed, 23 Jun 2010 18:59:42 GMT
Author: damien
Date: Wed Jun 23 18:59:42 2010
New Revision: 957303

URL: http://svn.apache.org/viewvc?rev=957303&view=rev
Log:
Make file deletions async to avoid pauses during compaction and db deletion. Fixes COUCHDB-780.

Modified:
    couchdb/trunk/src/couchdb/couch_db_updater.erl
    couchdb/trunk/src/couchdb/couch_file.erl
    couchdb/trunk/src/couchdb/couch_server.erl
    couchdb/trunk/src/couchdb/couch_view.erl
    couchdb/trunk/src/couchdb/couch_view_group.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=957303&r1=957302&r2=957303&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_db_updater.erl (original)
+++ couchdb/trunk/src/couchdb/couch_db_updater.erl Wed Jun 23 18:59:42 2010
@@ -27,7 +27,7 @@ init({MainPid, DbName, Filepath, Fd, Opt
         Header =  #db_header{},
         ok = couch_file:write_header(Fd, Header),
         % delete any old compaction files that might be hanging around
-        file:delete(Filepath ++ ".compact");
+        couch_file:delete(Filepath ++ ".compact");
     false ->
         ok = couch_file:upgrade_old_header(Fd, <<$g, $m, $k, 0>>), % 09 UPGRADE
CODE
         {ok, Header} = couch_file:read_header(Fd)
@@ -171,7 +171,7 @@ handle_cast({compact_done, CompactFilepa
 
         ?LOG_DEBUG("CouchDB swapping files ~s and ~s.",
                 [Filepath, CompactFilepath]),
-        file:delete(Filepath),
+        couch_file:delete(Filepath),
         ok = file:rename(CompactFilepath, Filepath),
         close_db(Db),
         ok = gen_server:call(Db#db.main_pid, {db_updated, NewDb2}),

Modified: couchdb/trunk/src/couchdb/couch_file.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_file.erl?rev=957303&r1=957302&r2=957303&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_file.erl (original)
+++ couchdb/trunk/src/couchdb/couch_file.erl Wed Jun 23 18:59:42 2010
@@ -28,6 +28,7 @@
 -export([pread_binary/2, read_header/1, truncate/2, upgrade_old_header/2]).
 -export([append_term_md5/2,append_binary_md5/2]).
 -export([init/1, terminate/2, handle_call/3, handle_cast/2, code_change/3, handle_info/2]).
+-export([delete/1]).
 
 %%----------------------------------------------------------------------
 %% Args:   Valid Options are [create] and [create,overwrite].
@@ -169,6 +170,15 @@ close(Fd) ->
         erlang:demonitor(MRef, [flush])
     end.
 
+delete(Filepath) ->
+    case file:rename(Filepath, Filepath ++ ".delete") of
+    ok ->
+        spawn(file, delete, [Filepath ++ ".delete"]),
+        ok;
+    Error ->
+        Error
+    end.
+
 % 09 UPGRADE CODE
 old_pread(Fd, Pos, Len) ->
     {ok, <<RawBin:Len/binary>>, false} = gen_server:call(Fd, {pread, Pos, Len},
infinity),

Modified: couchdb/trunk/src/couchdb/couch_server.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_server.erl?rev=957303&r1=957302&r2=957303&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_server.erl (original)
+++ couchdb/trunk/src/couchdb/couch_server.erl Wed Jun 23 18:59:42 2010
@@ -320,9 +320,9 @@ handle_call({delete, DbName, _Options}, 
 
         %% Delete any leftover .compact files.  If we don't do this a subsequent
         %% request for this DB will try to open the .compact file and use it.
-        file:delete(FullFilepath ++ ".compact"),
+        couch_file:delete(FullFilepath ++ ".compact"),
 
-        case file:delete(FullFilepath) of
+        case couch_file:delete(FullFilepath) of
         ok ->
             couch_db_update_notifier:notify({deleted, DbName}),
             {reply, ok, Server2};

Modified: couchdb/trunk/src/couchdb/couch_view.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_view.erl?rev=957303&r1=957302&r2=957303&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_view.erl (original)
+++ couchdb/trunk/src/couchdb/couch_view.erl Wed Jun 23 18:59:42 2010
@@ -94,7 +94,7 @@ cleanup_index_files(Db) ->
               re:run(FilePath, RegExp, [{capture, none}]) =:= nomatch],
     % delete unused files
     ?LOG_DEBUG("deleting unused view index files: ~p",[DeleteFiles]),
-    [file:delete(File)||File <- DeleteFiles],
+    [couch_file:delete(File)||File <- DeleteFiles],
     ok.
 
 list_index_files(Db) ->
@@ -316,7 +316,7 @@ do_reset_indexes(DbName, Root) ->
             delete_from_ets(Pid, DbName, Sig)
         end, Names),
     delete_index_dir(Root, DbName),
-    file:delete(Root ++ "/." ++ ?b2l(DbName) ++ "_temp").
+    couch_file:delete(Root ++ "/." ++ ?b2l(DbName) ++ "_temp").
 
 handle_info({'EXIT', FromPid, Reason}, Server) ->
     case ets:lookup(couch_groups_by_updater, FromPid) of

Modified: couchdb/trunk/src/couchdb/couch_view_group.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_view_group.erl?rev=957303&r1=957302&r2=957303&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_view_group.erl (original)
+++ couchdb/trunk/src/couchdb/couch_view_group.erl Wed Jun 23 18:59:42 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),
-    file:delete(FileName),
+    couch_file:delete(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) ->
-    file:delete(index_file_name(RootDir, DbName, GroupSig)).
+    couch_file:delete(index_file_name(RootDir, DbName, GroupSig)).
 
 init_group(Db, Fd, #group{views=Views}=Group, nil) ->
     init_group(Db, Fd, Group,



Mime
View raw message