summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien F. Katz <damien@apache.org>2010-06-23 18:59:42 +0000
committerDamien F. Katz <damien@apache.org>2010-06-23 18:59:42 +0000
commit918f8bf54a4aeffc3c0ef4ad1fa31ce93bbc1346 (patch)
tree5eee278fccc23e7ab893e8cf0b356db839d15677
parentf5fad72d00f5f3f0b38473898bb3683683a6cc49 (diff)
Make file deletions async to avoid pauses during compaction and db deletion. Fixes COUCHDB-780.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@957303 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/couchdb/couch_db_updater.erl4
-rw-r--r--src/couchdb/couch_file.erl10
-rw-r--r--src/couchdb/couch_server.erl4
-rw-r--r--src/couchdb/couch_view.erl4
-rw-r--r--src/couchdb/couch_view_group.erl4
5 files changed, 18 insertions, 8 deletions
diff --git a/src/couchdb/couch_db_updater.erl b/src/couchdb/couch_db_updater.erl
index 9a5476e8..c7c78dd2 100644
--- a/src/couchdb/couch_db_updater.erl
+++ b/src/couchdb/couch_db_updater.erl
@@ -27,7 +27,7 @@ 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
- 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, CompactFilepath}, #db{filepath=Filepath}=Db) ->
?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}),
diff --git a/src/couchdb/couch_file.erl b/src/couchdb/couch_file.erl
index 59074b65..fe524e24 100644
--- a/src/couchdb/couch_file.erl
+++ b/src/couchdb/couch_file.erl
@@ -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),
diff --git a/src/couchdb/couch_server.erl b/src/couchdb/couch_server.erl
index f2403ef7..c2313aef 100644
--- a/src/couchdb/couch_server.erl
+++ b/src/couchdb/couch_server.erl
@@ -320,9 +320,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.
- 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};
diff --git a/src/couchdb/couch_view.erl b/src/couchdb/couch_view.erl
index 6cdf3c56..ea4ffa58 100644
--- a/src/couchdb/couch_view.erl
+++ b/src/couchdb/couch_view.erl
@@ -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
diff --git a/src/couchdb/couch_view_group.erl b/src/couchdb/couch_view_group.erl
index 9c116759..8d3a3d86 100644
--- a/src/couchdb/couch_view_group.erl
+++ b/src/couchdb/couch_view_group.erl
@@ -186,7 +186,7 @@ handle_cast({compact_done, #group{current_seq=NewSeq} = NewGroup},
?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=Sig,name=Name} = Group) ->
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,