This is an automated email from the ASF dual-hosted git repository.

jiahuili430 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/main by this push:
     new a44ddb245 Improve `couch_debug.erl` (#5542)
a44ddb245 is described below

commit a44ddb2455fa646683989892425ee9984ab7ae8d
Author: Jiahui Li <[email protected]>
AuthorDate: Thu May 22 11:30:28 2025 -0500

    Improve `couch_debug.erl` (#5542)
    
    * Fix `mem3:ping/1` function clause error
    
    Error log:
    
    ```
    ** exception error: no function clause matching 
mem3:ping_nodes(['[email protected]']) (src/mem3.erl, line 453)
    ```
    
    * Improve `couch_debug.erl`
    
    - Add missing functions to `help/0`.
    - Export `print_tree/2` as it's already documented in `couch_debug:help/1` 
function.
    - Add a new line after each resource hoggers snapshot table for better 
viewing.
    - Add `couch_debug:ping_live_cluster_nodes/0`, and 
`ping_live_cluster_nodes/1`.
---
 src/couch/src/couch_debug.erl                  | 47 +++++++++++++++++++-------
 src/mem3/src/mem3.erl                          |  2 +-
 src/mem3/test/eunit/mem3_distribution_test.erl |  2 +-
 3 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/src/couch/src/couch_debug.erl b/src/couch/src/couch_debug.erl
index ff864210f..16af9d2da 100644
--- a/src/couch/src/couch_debug.erl
+++ b/src/couch/src/couch_debug.erl
@@ -48,7 +48,8 @@
     dead_nodes/1,
     ping/1,
     ping/2,
-    ping_nodes/0,
+    ping_live_cluster_nodes/0,
+    ping_live_cluster_nodes/1,
     ping_nodes/1,
     ping_nodes/2,
     node_events/0
@@ -57,9 +58,12 @@
 -export([
     print_table/2,
     print_report/1,
-    print_report_with_info_width/2
+    print_report_with_info_width/2,
+    print_tree/2
 ]).
 
+-define(PING_TIMEOUT_IN_MS, 60000).
+
 -type throw(_Reason) :: no_return().
 
 -type process_name() :: atom().
@@ -83,18 +87,23 @@ help() ->
         process_name,
         get_pid,
         link_tree,
-        mapfold,
-        map,
-        fold,
+        mapfold_tree,
+        fold_tree,
+        map_tree,
         linked_processes_info,
         print_linked_processes,
         memory_info,
+        resource_hoggers,
+        resource_hoggers_snapshot,
+        analyze_resource_hoggers,
         print_table,
         print_report,
         print_report_with_info_width,
+        print_tree,
         restart,
         restart_busy,
         dead_nodes,
+        ping,
         ping_nodes,
         node_events
     ].
@@ -467,18 +476,27 @@ help(ping) ->
 
         Ping a node and return either a time in microseconds or an error term.
 
+        ---
+    ", []);
+help(ping_live_cluster_nodes) ->
+    io:format("
+        ping_live_cluster_nodes()
+        ping_live_cluster_nodes(Timeout)
+        --------------------------------
+
+        Ping the currently connected cluster nodes. Returns a list of
+        {Node, Result} tuples or an empty list.
+
         ---
     ", []);
 help(ping_nodes) ->
     io:format("
-        ping_nodes()
-        ping_nodes(Timeout)
+        ping_nodes(Nodes)
         ping_nodes(Nodes, Timeout)
         --------------------------------
 
-        Ping the list of currently connected nodes. Return a list of {Node,
-        Result} tuples where Result is either a time in microseconds or an
-        error term.
+        Ping the list of nodes. Return a list of {Node, Result} tuples where
+        Result is either a time in microseconds or an error term.
 
         ---
     ", []);
@@ -768,6 +786,7 @@ info_size(InfoKV) ->
         {binary, BinInfos} -> lists:sum([S || {_, S, _} <- BinInfos]);
         {_, V} -> V
     end.
+
 resource_hoggers(MemoryInfo, InfoKey) ->
     KeyFun = fun
         ({_Pid, _Id, undefined}) -> undefined;
@@ -976,12 +995,15 @@ ping(Node) ->
 ping(Node, Timeout) ->
     mem3:ping(Node, Timeout).
 
-ping_nodes() ->
+ping_live_cluster_nodes() ->
     mem3:ping_nodes().
 
-ping_nodes(Timeout) ->
+ping_live_cluster_nodes(Timeout) ->
     mem3:ping_nodes(Timeout).
 
+ping_nodes(Nodes) ->
+    mem3:ping_nodes(Nodes, ?PING_TIMEOUT_IN_MS).
+
 ping_nodes(Nodes, Timeout) ->
     mem3:ping_nodes(Nodes, Timeout).
 
@@ -1007,6 +1029,7 @@ print_table(Rows, TableSpec) ->
         end,
         Rows
     ),
+    io:format("~n", []),
     ok.
 
 print_report(Report) ->
diff --git a/src/mem3/src/mem3.erl b/src/mem3/src/mem3.erl
index c0d64d7e4..5e419ea12 100644
--- a/src/mem3/src/mem3.erl
+++ b/src/mem3/src/mem3.erl
@@ -434,7 +434,7 @@ engine(Opts) when is_list(Opts) ->
 -spec ping(node()) -> pos_integer() | Error :: term().
 
 ping(Node) ->
-    [{Node, Res}] = ping_nodes([Node]),
+    [{Node, Res}] = ping_nodes([Node], ?PING_TIMEOUT_IN_MS),
     Res.
 
 -spec ping(node(), Timeout :: pos_integer()) -> pos_integer() | Error :: 
term().
diff --git a/src/mem3/test/eunit/mem3_distribution_test.erl 
b/src/mem3/test/eunit/mem3_distribution_test.erl
index 4bccc872b..22dcfd7fa 100644
--- a/src/mem3/test/eunit/mem3_distribution_test.erl
+++ b/src/mem3/test/eunit/mem3_distribution_test.erl
@@ -136,7 +136,7 @@ ping_nodes_test(_) ->
             {n1, {nodedown, n1}},
             {n2, {nodedown, n2}}
         ],
-        couch_debug:ping_nodes()
+        couch_debug:ping_live_cluster_nodes()
     ),
     ?assertEqual({nodedown, n3}, couch_debug:ping(n3, 100)).
 

Reply via email to