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

laiyingchun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git


The following commit(s) were added to refs/heads/master by this push:
     new abd1794a2 refactor(FQDN): update some logs in cpp-shell CLI (#2064)
abd1794a2 is described below

commit abd1794a29f1affd65b54b3278b5d4ec64d9bef0
Author: Yingchun Lai <[email protected]>
AuthorDate: Mon Jul 15 15:02:05 2024 +0800

    refactor(FQDN): update some logs in cpp-shell CLI (#2064)
---
 src/shell/command_utils.cpp            | 20 +++++++++++---------
 src/shell/command_utils.h              |  2 +-
 src/shell/commands/detect_hotkey.cpp   |  6 +++---
 src/shell/commands/node_management.cpp |  2 +-
 src/shell/commands/recovery.cpp        |  4 ++--
 src/shell/main.cpp                     |  8 ++++----
 6 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/src/shell/command_utils.cpp b/src/shell/command_utils.cpp
index fb3be3bce..96e5235a0 100644
--- a/src/shell/command_utils.cpp
+++ b/src/shell/command_utils.cpp
@@ -26,30 +26,32 @@
 #include "utils/error_code.h"
 
 bool validate_ip(shell_context *sc,
-                 const std::string &ip_str,
+                 const std::string &target_hp_str,
                  dsn::host_port &target_hp,
                  std::string &err_info)
 {
-    target_hp = dsn::host_port::from_string(ip_str);
+    target_hp = dsn::host_port::from_string(target_hp_str);
     if (!target_hp) {
-        err_info = fmt::format("invalid ip:port={}, can't transform it into 
host_port", ip_str);
+        err_info =
+            fmt::format("invalid host:port '{}', can't transform it into 
host_port", target_hp_str);
         return false;
     }
 
-    std::map<dsn::host_port, dsn::replication::node_status::type> nodes;
-    auto error = 
sc->ddl_client->list_nodes(dsn::replication::node_status::NS_INVALID, nodes);
+    std::map<dsn::host_port, dsn::replication::node_status::type> ns_by_nodes;
+    const auto error =
+        sc->ddl_client->list_nodes(dsn::replication::node_status::NS_INVALID, 
ns_by_nodes);
     if (error != dsn::ERR_OK) {
-        err_info = fmt::format("list nodes failed, error={}", 
error.to_string());
+        err_info = fmt::format("list nodes failed, error={}", error);
         return false;
     }
 
-    for (const auto &node : nodes) {
-        if (target_hp == node.first) {
+    for (const auto &[node, _] : ns_by_nodes) {
+        if (target_hp == node) {
             return true;
         }
     }
 
-    err_info = fmt::format("invalid ip:port={}, can't find it in the cluster", 
ip_str);
+    err_info = fmt::format("invalid host:port '{}', can't find it in the 
cluster", target_hp_str);
     return false;
 }
 
diff --git a/src/shell/command_utils.h b/src/shell/command_utils.h
index 5e1095d9a..e076c3d32 100644
--- a/src/shell/command_utils.h
+++ b/src/shell/command_utils.h
@@ -66,7 +66,7 @@ inline bool validate_cmd(const argh::parser &cmd,
 }
 
 bool validate_ip(shell_context *sc,
-                 const std::string &ip_str,
+                 const std::string &host_port_str,
                  /*out*/ dsn::host_port &target_hp,
                  /*out*/ std::string &err_info);
 
diff --git a/src/shell/commands/detect_hotkey.cpp 
b/src/shell/commands/detect_hotkey.cpp
index c78f906c6..05acc7cd0 100644
--- a/src/shell/commands/detect_hotkey.cpp
+++ b/src/shell/commands/detect_hotkey.cpp
@@ -102,8 +102,8 @@ bool detect_hotkey(command_executor *e, shell_context *sc, 
arguments args)
 
     dsn::host_port target_hp;
     std::string err_info;
-    std::string ip_str = cmd({"-d", "--address"}).str();
-    if (!validate_ip(sc, ip_str, target_hp, err_info)) {
+    const auto &target_hp_str = cmd({"-d", "--address"}).str();
+    if (!validate_ip(sc, target_hp_str, target_hp, err_info)) {
         fmt::print(stderr, "{}\n", err_info);
         return false;
     }
@@ -145,7 +145,7 @@ bool detect_hotkey(command_executor *e, shell_context *sc, 
arguments args)
                    app_id,
                    partition_index,
                    hotkey_type,
-                   ip_str);
+                   target_hp_str);
         break;
     case dsn::replication::detect_action::STOP:
         fmt::print("Hotkey detection is stopped now\n");
diff --git a/src/shell/commands/node_management.cpp 
b/src/shell/commands/node_management.cpp
index abf4c7f75..a18b9ef8d 100644
--- a/src/shell/commands/node_management.cpp
+++ b/src/shell/commands/node_management.cpp
@@ -638,7 +638,7 @@ bool remote_command(command_executor *e, shell_context *sc, 
arguments args)
         for (std::string &token : tokens) {
             const auto node = dsn::host_port::from_string(token);
             if (!node) {
-                fprintf(stderr, "parse %s as a ip:port node failed\n", 
token.c_str());
+                fprintf(stderr, "parse %s as a host:port node failed\n", 
token.c_str());
                 return true;
             }
             node_list.emplace_back("user-specified", node);
diff --git a/src/shell/commands/recovery.cpp b/src/shell/commands/recovery.cpp
index b7c8ce106..dfd82122b 100644
--- a/src/shell/commands/recovery.cpp
+++ b/src/shell/commands/recovery.cpp
@@ -118,7 +118,7 @@ bool recover(command_executor *e, shell_context *sc, 
arguments args)
         for (std::string &token : tokens) {
             const auto node = dsn::host_port::from_string(token);
             if (!node) {
-                fprintf(stderr, "parse %s as a ip:port node failed\n", 
token.c_str());
+                fprintf(stderr, "parse %s as a host:port node failed\n", 
token.c_str());
                 return true;
             }
             node_list.push_back(node);
@@ -140,7 +140,7 @@ bool recover(command_executor *e, shell_context *sc, 
arguments args)
             const auto node = dsn::host_port::from_string(str);
             if (!node) {
                 fprintf(stderr,
-                        "parse %s at file %s line %d as ip:port failed\n",
+                        "parse %s at file %s line %d as host:port failed\n",
                         str.c_str(),
                         node_list_file.c_str(),
                         lineno);
diff --git a/src/shell/main.cpp b/src/shell/main.cpp
index e8533d0d8..a6df779fe 100644
--- a/src/shell/main.cpp
+++ b/src/shell/main.cpp
@@ -372,20 +372,20 @@ static command_executor commands[] = {
     {
         "remote_command",
         "send remote command to servers",
-        "[-t all|meta-server|replica-server] [-r|--resolve_ip] [-l 
ip:port,ip:port...]"
+        "[-t all|meta-server|replica-server] [-r|--resolve_ip] [-l 
host:port,host:port...]"
         " <command> [arguments...]",
         remote_command,
     },
     {
         "server_info",
         "get info of servers",
-        "[-t all|meta-server|replica-server] [-l ip:port,ip:port...] 
[-r|--resolve_ip]",
+        "[-t all|meta-server|replica-server] [-l host:port,host:port...] 
[-r|--resolve_ip]",
         server_info,
     },
     {
         "server_stat",
         "get stat of servers",
-        "[-t all|meta-server|replica-server] [-l ip:port,ip:port...] 
[-r|--resolve_ip]",
+        "[-t all|meta-server|replica-server] [-l host:port,host:port...] 
[-r|--resolve_ip]",
         server_stat,
     },
     {
@@ -398,7 +398,7 @@ static command_executor commands[] = {
     {
         "flush_log",
         "flush log of servers",
-        "[-t all|meta-server|replica-server] [-l 
ip:port,ip:port...][-r|--resolve_ip]",
+        "[-t all|meta-server|replica-server] [-l 
host:port,host:port...][-r|--resolve_ip]",
         flush_log,
     },
     {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to