summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_file.erl
diff options
context:
space:
mode:
authorDamien F. Katz <damien@apache.org>2009-04-09 21:37:23 +0000
committerDamien F. Katz <damien@apache.org>2009-04-09 21:37:23 +0000
commitcdf43ab5a1d5ea21e42302c848fe4f07150e6947 (patch)
tree431279b218c6bb13454dcfc73286b45c1f9a690d /src/couchdb/couch_file.erl
parentcf3eac0fc97cc4671c1ba86e1924b0a46d096333 (diff)
Fix for attachment sparseness bug COUCHDB-220 by giving each attachment it's own stream and calling set_min_buffer instead of ensure_buffer. Also fixed spurious couch_file crash messages by putting the statistics decrement code into a seperate monitoring process.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@763816 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_file.erl')
-rw-r--r--src/couchdb/couch_file.erl26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/couchdb/couch_file.erl b/src/couchdb/couch_file.erl
index ecab455b..93c43434 100644
--- a/src/couchdb/couch_file.erl
+++ b/src/couchdb/couch_file.erl
@@ -269,7 +269,6 @@ init_status_error(ReturnPid, Ref, Error) ->
% server functions
init({Filepath, Options, ReturnPid, Ref}) ->
- process_flag(trap_exit, true),
case lists:member(create, Options) of
true ->
filelib:ensure_dir(Filepath),
@@ -285,14 +284,14 @@ init({Filepath, Options, ReturnPid, Ref}) ->
true ->
{ok, 0} = file:position(Fd, 0),
ok = file:truncate(Fd),
- catch couch_stats_collector:increment({couchdb, open_os_files}),
+ track_stats(),
{ok, Fd};
false ->
ok = file:close(Fd),
init_status_error(ReturnPid, Ref, file_exists)
end;
false ->
- catch couch_stats_collector:increment({couchdb, open_os_files}),
+ track_stats(),
{ok, Fd}
end;
Error ->
@@ -304,7 +303,7 @@ init({Filepath, Options, ReturnPid, Ref}) ->
{ok, Fd_Read} ->
{ok, Fd} = file:open(Filepath, [read, write, raw, binary]),
ok = file:close(Fd_Read),
- catch couch_stats_collector:increment({couchdb, open_os_files}),
+ track_stats(),
{ok, Fd};
Error ->
init_status_error(ReturnPid, Ref, Error)
@@ -312,10 +311,21 @@ init({Filepath, Options, ReturnPid, Ref}) ->
end.
-terminate(_Reason, _Fd) ->
- catch couch_stats_collector:decrement({couchdb, open_os_files}),
+terminate(_Reason, _Fd) ->
ok.
+track_stats() ->
+ try couch_stats_collector:increment({couchdb, open_os_files}) of
+ ok ->
+ Self = self(),
+ spawn(
+ fun() ->
+ erlang:monitor(process, Self),
+ receive {'DOWN', _, _, _, _} -> ok end,
+ couch_stats_collector:decrement({couchdb, open_os_files})
+ end)
+ catch _ -> ok
+ end.
handle_call({pread, Pos, Bytes}, _From, Fd) ->
{reply, file:pread(Fd, Pos, Bytes), Fd};
@@ -349,5 +359,5 @@ handle_cast(close, Fd) ->
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
-handle_info({'EXIT', _, Reason}, Fd) ->
- {stop, Reason, Fd}.
+handle_info(foo, _Fd) ->
+ ok.