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 2014/02/05 00:06:45 UTC

[32/50] couch commit: updated refs/heads/import to c3116d7

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/4fcb3b15
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/4fcb3b15
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/4fcb3b15

Branch: refs/heads/import
Commit: 4fcb3b157da7b25b7137cb24c7e66aff6e5cbfe5
Parents: 68d60f0
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Mar 13 03:52:07 2013 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Tue Feb 4 17:03:25 2014 -0600

----------------------------------------------------------------------
 src/couch_file.erl | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/4fcb3b15/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;