Skip to content

Fix couch_debug:opened_files* functions#4075

Merged
nickva merged 1 commit intomainfrom
fix-couch-debug-opened-files
Jun 20, 2022
Merged

Fix couch_debug:opened_files* functions#4075
nickva merged 1 commit intomainfrom
fix-couch-debug-opened-files

Conversation

@nickva
Copy link
Contributor

@nickva nickva commented Jun 20, 2022

They relied on scanning async IO thread pool ports (efile) before . That only worked in Erlang versions < 21. Since then file IO was moved to dirty schedulers so listing efile ports doesn't yield any useful results.

The partial fix is iterate through processes() and pick out the ones for which couch_file has put anything into the process dictionary. This will skip non-couch-file files but it's probably still better than nothing.

They relied on scanning async IO thread pool ports (`efile`) before . That only
worked in Erlang versions < 21. Since then file IO was moved to dirty
schedulers so listing efile ports doesn't yield any useful results.

The partial fix is iterate through `processes()` and pick out the ones for
which couch_file has put anything into the process dictionary. This will skip
non-couch-file files but it's probably still better than nothing.
@nickva
Copy link
Contributor Author

nickva commented Jun 20, 2022

Example of usage:

(node1@127.0.0.1)1> couch_debug:opened_files().
[{<0.417.0>,
  {file_descriptor,prim_file,
                   #{handle => #Ref<0.3584905603.118358043.227800>,
                     owner => <0.417.0>,r_ahead_size => 0,
                     r_buffer => #Ref<0.3584905603.118358017.227799>}},
  "/Users/nvatama/asf/dev/lib/node1/data/_nodes.couch"},
 {<0.434.0>,
  {file_descriptor,prim_file,
                   #{handle => #Ref<0.3584905603.118358046.228058>,
                     owner => <0.434.0>,r_ahead_size => 0,
                     r_buffer => #Ref<0.3584905603.118358017.227932>}},
  "/Users/nvatama/asf/dev/lib/node1/data/_dbs.couch"},
 ...
(node1@127.0.0.1)3> couch_debug:opened_files_contains("_replicator").
[{<0.790.0>,
  {file_descriptor,prim_file,
                   #{handle => #Ref<0.3584905603.118358045.227768>,
                     owner => <0.790.0>,r_ahead_size => 0,
                     r_buffer => #Ref<0.3584905603.118358018.227921>}},
  "/Users/nvatama/asf/dev/lib/node1/data/shards/00000000-7fffffff/_replicator.1655761414.couch"},
 couch_debug:opened_files_by_regexp(".*_replicator.*").
[{<0.790.0>,
  {file_descriptor,prim_file,
                   #{handle => #Ref<0.3584905603.118358045.227768>,
                     owner => <0.790.0>,r_ahead_size => 0,
                     r_buffer => #Ref<0.3584905603.118358018.227921>}},
  "/Users/nvatama/asf/dev/lib/node1/data/shards/00000000-7fffffff/_replicator.1655761414.couch"},

Copy link
Contributor

@jaydoane jaydoane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work as expected:

(node1@127.0.0.1)8> length(couch_debug:opened_files()).
132

(node1@127.0.0.1)9> length(couch_debug:opened_files_contains("_global_change")).
8

(node1@127.0.0.1)10> length(couch_debug:opened_files_by_regexp(".*_global.*")).
8

@nickva nickva merged commit 116c4e9 into main Jun 20, 2022
@nickva nickva deleted the fix-couch-debug-opened-files branch June 20, 2022 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants