diff --git a/src/shell/command_utils.cpp b/src/shell/command_utils.cpp index fb3be3bced..96e5235a0b 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 nodes; - auto error = sc->ddl_client->list_nodes(dsn::replication::node_status::NS_INVALID, nodes); + std::map 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 5e1095d9a1..e076c3d32d 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 c78f906c67..05acc7cd04 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 abf4c7f750..a18b9ef8d6 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 b7c8ce1063..dfd82122b9 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 e8533d0d8d..a6df779fe9 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...]" " [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, }, {