Correctly (don't) track sys_db files
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/a89af584 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/a89af584 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/a89af584 Branch: refs/heads/import Commit: a89af5843aff55688465a5815200706fe25dc453 Parents: fbff267 Author: Paul J. Davis <[email protected]> Authored: Wed Mar 13 03:52:07 2013 -0500 Committer: Paul J. Davis <[email protected]> Committed: Fri Jan 17 16:44:32 2014 -0800 ---------------------------------------------------------------------- src/couch_file.erl | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/a89af584/src/couch_file.erl ---------------------------------------------------------------------- diff --git a/src/couch_file.erl b/src/couch_file.erl index a638c32..7528091 100644 --- a/src/couch_file.erl +++ b/src/couch_file.erl @@ -23,6 +23,7 @@ -record(file, { fd, + is_sys, eof = 0, db_pid }). @@ -306,7 +307,7 @@ init({Filepath, Options, ReturnPid, Ref}) -> ok = file:sync(Fd), maybe_track_open_os_files(Options), erlang:send_after(?INITIAL_WAIT, self(), maybe_close), - {ok, #file{fd=Fd}}; + {ok, #file{fd=Fd, is_sys=lists:member(sys_db, Options)}}; false -> ok = file:close(Fd), init_status_error(ReturnPid, Ref, {error, eexist}) @@ -314,7 +315,7 @@ init({Filepath, Options, ReturnPid, Ref}) -> false -> maybe_track_open_os_files(Options), erlang:send_after(?INITIAL_WAIT, self(), maybe_close), - {ok, #file{fd=Fd}} + {ok, #file{fd=Fd, is_sys=lists:member(sys_db, Options)}} end; Error -> init_status_error(ReturnPid, Ref, Error) @@ -328,7 +329,7 @@ init({Filepath, Options, ReturnPid, Ref}) -> maybe_track_open_os_files(Options), {ok, Eof} = file:position(Fd, eof), erlang:send_after(?INITIAL_WAIT, self(), maybe_close), - {ok, #file{fd=Fd, eof=Eof}}; + {ok, #file{fd=Fd, eof=Eof, is_sys=lists:member(sys_db, Options)}}; Error -> init_status_error(ReturnPid, Ref, Error) end @@ -437,7 +438,7 @@ code_change(_OldVsn, State, _Extra) -> {ok, State}. handle_info(maybe_close, File) -> - case is_idle() of + case is_idle(File) of true -> {stop, normal, File}; false -> @@ -446,7 +447,7 @@ handle_info(maybe_close, File) -> end; handle_info({'EXIT', Pid, _}, #file{db_pid=Pid}=File) -> - case is_idle() of + case is_idle(File) of true -> {stop, normal, File}; false -> {noreply, File} end; @@ -572,7 +573,13 @@ split_iolist([Byte | Rest], SplitAt, BeginAcc) when is_integer(Byte) -> split_iolist(Rest, SplitAt - 1, [Byte | BeginAcc]). -is_idle() -> +% System dbs aren't monitored by couch_stats_collector +is_idle(#file{is_sys=true}) -> + case process_info(self(), monitored_by) of + {monitored_by, []} -> true; + _ -> false + end; +is_idle(#file{is_sys=false}) -> case process_info(self(), monitored_by) of {monitored_by, []} -> true; {monitored_by, [_]} -> true;
