summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDamien F. Katz <damien@apache.org>2010-07-03 04:25:06 +0000
committerDamien F. Katz <damien@apache.org>2010-07-03 04:25:06 +0000
commitc7117e17bed9cc0dec38264ee31463d5ef56ac4c (patch)
treecbfa756df445aefce25dcc6399e045e83c2efd31 /src
parentd0e2510ccb74b61a62e32f75c35396f62556c2f7 (diff)
Fix deletion to move properly to root of storage, to avoid copying files when view and database dirs are on different mounts.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@960153 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/couchdb/couch_db_updater.erl6
-rw-r--r--src/couchdb/couch_file.erl24
-rw-r--r--src/couchdb/couch_server.erl6
-rw-r--r--src/couchdb/couch_view.erl15
4 files changed, 32 insertions, 19 deletions
diff --git a/src/couchdb/couch_db_updater.erl b/src/couchdb/couch_db_updater.erl
index 5042e3cb..30275012 100644
--- a/src/couchdb/couch_db_updater.erl
+++ b/src/couchdb/couch_db_updater.erl
@@ -27,7 +27,8 @@ init({MainPid, DbName, Filepath, Fd, Options}) ->
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, CompactFilepath}, #db{filepath=Filepath}=Db) ->
?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}),
diff --git a/src/couchdb/couch_file.erl b/src/couchdb/couch_file.erl
index b130c1db..0a891712 100644
--- a/src/couchdb/couch_file.erl
+++ b/src/couchdb/couch_file.erl
@@ -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")),
diff --git a/src/couchdb/couch_server.erl b/src/couchdb/couch_server.erl
index 84a02d13..43fd9044 100644
--- a/src/couchdb/couch_server.erl
+++ b/src/couchdb/couch_server.erl
@@ -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}, _From, Server) ->
%% 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};
diff --git a/src/couchdb/couch_view.erl b/src/couchdb/couch_view.erl
index ea4ffa58..38c0a783 100644
--- a/src/couchdb/couch_view.erl
+++ b/src/couchdb/couch_view.erl
@@ -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),