You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2010/07/03 06:25:08 UTC

svn commit: r960153 - in /couchdb/trunk/src/couchdb: couch_db_updater.erl couch_file.erl couch_server.erl couch_view.erl

Author: damien
Date: Sat Jul  3 04:25:06 2010
New Revision: 960153

URL: http://svn.apache.org/viewvc?rev=960153&view=rev
Log:
Fix deletion to move properly to root of storage, to avoid copying files when view and database dirs are on different mounts.

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

Modified: couchdb/trunk/src/couchdb/couch_db_updater.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_db_updater.erl?rev=960153&r1=960152&r2=960153&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_db_updater.erl (original)
+++ couchdb/trunk/src/couchdb/couch_db_updater.erl Sat Jul  3 04:25:06 2010
@@ -27,7 +27,8 @@ 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
-        couch_file:delete(Filepath ++ ".compact");
+        RootDir = couch_config:get("couchdb", "database_dir", "."),
+        couch_file:delete(RootDir, Filepath ++ ".compact");
     false ->
         ok = couch_file:upgrade_old_header(Fd, <<$g, $m, $k, 0>>), % 09 UPGRADE CODE
         case couch_file:read_header(Fd) of
@@ -180,7 +181,8 @@ handle_cast({compact_done, CompactFilepa
 
         ?LOG_DEBUG("CouchDB swapping files ~s and ~s.",
                 [Filepath, CompactFilepath]),
-        couch_file:delete(Filepath),
+        RootDir = couch_config:get("couchdb", "database_dir", "."),
+        couch_file:delete(RootDir, 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=960153&r1=960152&r2=960153&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_file.erl (original)
+++ couchdb/trunk/src/couchdb/couch_file.erl Sat Jul  3 04:25:06 2010
@@ -28,7 +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,init_delete_dir/0]).
+-export([delete/2,delete/3,init_delete_dir/1]).
 
 %%----------------------------------------------------------------------
 %% Args:   Valid Options are [create] and [create,overwrite].
@@ -170,20 +170,28 @@ close(Fd) ->
         erlang:demonitor(MRef, [flush])
     end.
 
-delete(Filepath) ->
-    DbDir = couch_config:get("couchdb", "database_dir"),
-    DelFile = filename:join([DbDir,".delete", ?b2l(couch_uuids:random())]),
+
+delete(RootDir, Filepath) ->
+    delete(RootDir, Filepath, true).
+
+
+delete(RootDir, Filepath, Async) ->
+    DelFile = filename:join([RootDir,".delete", ?b2l(couch_uuids:random())]),
     case file:rename(Filepath, DelFile) of
     ok ->
-        spawn(file, delete, [DelFile]),
-        ok;
+        if (Async) ->
+            spawn(file, delete, [DelFile]),
+            ok;
+        true ->
+            file:delete(DelFile)
+        end;
     Error ->
         Error
     end.
 
 
-init_delete_dir() ->
-    Dir = filename:join(couch_config:get("couchdb","database_dir"),".delete"),
+init_delete_dir(RootDir) ->
+    Dir = filename:join(RootDir,".delete"),
     % note: ensure_dir requires an actual filename companent, which is the
     % reason for "foo".
     filelib:ensure_dir(filename:join(Dir,"foo")),

Modified: couchdb/trunk/src/couchdb/couch_server.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_server.erl?rev=960153&r1=960152&r2=960153&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_server.erl (original)
+++ couchdb/trunk/src/couchdb/couch_server.erl Sat Jul  3 04:25:06 2010
@@ -131,7 +131,7 @@ init([]) ->
             gen_server:call(couch_server,
                     {set_max_dbs_open, list_to_integer(Max)})
         end),
-    ok = couch_file:init_delete_dir(),
+    ok = couch_file:init_delete_dir(RootDir),
     hash_admin_passwords(),
     ok = couch_config:register(
         fun("admins", _Key, _Value, Persist) ->
@@ -351,9 +351,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.
-        couch_file:delete(FullFilepath ++ ".compact"),
+        couch_file:delete(Server#server.root_dir, FullFilepath ++ ".compact"),
 
-        case couch_file:delete(FullFilepath) of
+        case couch_file:delete(Server#server.root_dir, 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=960153&r1=960152&r2=960153&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_view.erl (original)
+++ couchdb/trunk/src/couchdb/couch_view.erl Sat Jul  3 04:25:06 2010
@@ -94,7 +94,8 @@ cleanup_index_files(Db) ->
               re:run(FilePath, RegExp, [{capture, none}]) =:= nomatch],
     % delete unused files
     ?LOG_DEBUG("deleting unused view index files: ~p",[DeleteFiles]),
-    [couch_file:delete(File)||File <- DeleteFiles],
+    RootDir = couch_config:get("couchdb", "view_index_dir"),
+    [couch_file:delete(RootDir,File,false)||File <- DeleteFiles],
     ok.
 
 list_index_files(Db) ->
@@ -266,6 +267,7 @@ init([]) ->
     ets:new(group_servers_by_sig, [set, protected, named_table]),
     ets:new(couch_groups_by_updater, [set, private, named_table]),
     process_flag(trap_exit, true),
+    ok = couch_file:init_delete_dir(RootDir),
     {ok, #server{root_dir=RootDir}}.
 
 
@@ -316,7 +318,8 @@ do_reset_indexes(DbName, Root) ->
             delete_from_ets(Pid, DbName, Sig)
         end, Names),
     delete_index_dir(Root, DbName),
-    couch_file:delete(Root ++ "/." ++ ?b2l(DbName) ++ "_temp").
+    RootDelDir = couch_config:get("couchdb", "view_index_dir"),
+    couch_file:delete(RootDelDir, Root ++ "/." ++ ?b2l(DbName) ++ "_temp").
 
 handle_info({'EXIT', FromPid, Reason}, Server) ->
     case ets:lookup(couch_groups_by_updater, FromPid) of
@@ -347,19 +350,19 @@ code_change(_OldVsn, State, _Extra) ->
 
 
 delete_index_dir(RootDir, DbName) ->
-    nuke_dir(RootDir ++ "/." ++ ?b2l(DbName) ++ "_design").
+    nuke_dir(RootDir, RootDir ++ "/." ++ ?b2l(DbName) ++ "_design").
 
-nuke_dir(Dir) ->
+nuke_dir(RootDelDir, Dir) ->
     case file:list_dir(Dir) of
     {error, enoent} -> ok; % doesn't exist
     {ok, Files} ->
         lists:foreach(
             fun(File)->
                 Full = Dir ++ "/" ++ File,
-                case file:delete(Full) of
+                case couch_file:delete(RootDelDir, Full, false) of
                 ok -> ok;
                 {error, eperm} ->
-                    ok = nuke_dir(Full)
+                    ok = nuke_dir(RootDelDir, Full)
                 end
             end,
             Files),