You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ii...@apache.org on 2016/02/17 01:19:43 UTC

[1/2] couch commit: updated refs/heads/master to e928e83

Repository: couchdb-couch
Updated Branches:
  refs/heads/master f3b7f5a47 -> e928e83bd


Add couch_debug:opened_files/0

This function is for debugging purposes only. It iterates through all
open ports and returns file descriptor and filename correspondent to
every port.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/08e2a04e
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/08e2a04e
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/08e2a04e

Branch: refs/heads/master
Commit: 08e2a04e435c02ab71a041dac671b616551d2753
Parents: f3b7f5a
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Thu Jan 28 13:17:42 2016 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 16 15:51:26 2016 -0800

----------------------------------------------------------------------
 src/couch_debug.erl | 33 +++++++++++++++++++++++++++++++++
 src/couch_file.erl  | 18 ++++++++++++++++++
 2 files changed, 51 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/08e2a04e/src/couch_debug.erl
----------------------------------------------------------------------
diff --git a/src/couch_debug.erl b/src/couch_debug.erl
new file mode 100644
index 0000000..31b4c5c
--- /dev/null
+++ b/src/couch_debug.erl
@@ -0,0 +1,33 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_debug).
+
+-export([opened_files/0]).
+
+-spec opened_files() ->
+    [{port(), CouchFilePid :: pid(), Fd :: pid() | tuple(), FilePath :: string()}].
+
+opened_files() ->
+    Info = [couch_file_port_info(Port)
+        || Port <- erlang:ports(),
+            {name, "efile"} =:= erlang:port_info(Port, name)],
+    [I || I <- Info, is_tuple(I)].
+
+couch_file_port_info(Port) ->
+    {connected, Pid} = erlang:port_info(Port, connected),
+    case couch_file:process_info(Pid) of
+        {Fd, FilePath} ->
+            {Port, Pid, Fd, FilePath};
+        undefined ->
+            undefined
+    end.

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/08e2a04e/src/couch_file.erl
----------------------------------------------------------------------
diff --git a/src/couch_file.erl b/src/couch_file.erl
index e6cd01a..f6c5a4f 100644
--- a/src/couch_file.erl
+++ b/src/couch_file.erl
@@ -42,6 +42,8 @@
 -export([init/1, terminate/2, code_change/3]).
 -export([handle_call/3, handle_cast/2, handle_info/2]).
 
+%% helper functions
+-export([process_info/1]).
 
 %%----------------------------------------------------------------------
 %% Args:   Valid Options are [create] and [create,overwrite].
@@ -299,6 +301,8 @@ init({Filepath, Options, ReturnPid, Ref}) ->
         filelib:ensure_dir(Filepath),
         case file:open(Filepath, OpenOptions) of
         {ok, Fd} ->
+            %% Save Fd in process dictionary for debugging purposes
+            put(couch_file_fd, {Fd, Filepath}),
             {ok, Length} = file:position(Fd, eof),
             case Length > 0 of
             true ->
@@ -330,6 +334,8 @@ init({Filepath, Options, ReturnPid, Ref}) ->
         case file:open(Filepath, [read, raw]) of
         {ok, Fd_Read} ->
             {ok, Fd} = file:open(Filepath, OpenOptions),
+            %% Save Fd in process dictionary for debugging purposes
+            put(couch_file_fd, {Fd, Filepath}),
             ok = file:close(Fd_Read),
             maybe_track_open_os_files(Options),
             {ok, Eof} = file:position(Fd, eof),
@@ -592,3 +598,15 @@ is_idle(#file{is_sys=false}) ->
         {monitored_by, [_]} -> exit(tracker_monitoring_failed);
         _ -> false
     end.
+
+-spec process_info(CouchFilePid :: pid()) ->
+    {Fd :: pid() | tuple(), FilePath :: string()}.
+
+process_info(Pid) ->
+    {dictionary, Dict} = erlang:process_info(Pid, dictionary),
+    case lists:keyfind(couch_file_fd, 1, Dict) of
+        false ->
+            undefined;
+        {couch_file_fd, {Fd, InitialName}} ->
+            {Fd, InitialName}
+    end.


[2/2] couch commit: updated refs/heads/master to e928e83

Posted by ii...@apache.org.
Merge remote-tracking branch 'github/pr/135'


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/e928e83b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/e928e83b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/e928e83b

Branch: refs/heads/master
Commit: e928e83bdb996dd69c8d70920c6eadcec47155cb
Parents: f3b7f5a 08e2a04
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Feb 16 15:55:17 2016 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 16 15:55:17 2016 -0800

----------------------------------------------------------------------
 src/couch_debug.erl | 33 +++++++++++++++++++++++++++++++++
 src/couch_file.erl  | 18 ++++++++++++++++++
 2 files changed, 51 insertions(+)
----------------------------------------------------------------------