Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Smityz committed Sep 29, 2020
1 parent aeb7845 commit c0c39ca
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/general_question.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Before asking a question, make sure you have:

- Searched open and closed [GitHub issues](https://github.com/XiaoMi/pegasus/issues)
- Read the documentation:
- [Pegasus Doc](https://pegasus-kv.github.io)
- [Pegasus Doc](https://pegasus.apache.org)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[pegasus-rocksdb]: https://github.com/xiaomi/pegasus-rocksdb
[facebook-rocksdb]: https://github.com/facebook/rocksdb
[hbase]: https://hbase.apache.org/
[website]: https://pegasus-kv.github.io
[website]: https://pegasus.apache.org

![pegasus-logo](docs/media-img/pegasus-logo.png)

Expand Down
33 changes: 33 additions & 0 deletions src/shell/command_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "command_utils.h"

bool validate_ip(shell_context *sc,
const std::string &ip_str,
/*out*/ dsn::rpc_address &target_address,
/*out*/ std::string &err_info)
{
std::map<dsn::rpc_address, dsn::replication::node_status::type> nodes;
auto error = sc->ddl_client->list_nodes(::dsn::replication::node_status::NS_INVALID, nodes);
if (error != dsn::ERR_OK) {
err_info = fmt::format("list nodes failed, error={} \n", error.to_string());
return false;
}

if (!target_address.from_string_ipv4(ip_str.c_str())) {
err_info = fmt::format("invalid ip:port:{}, can't transform it into rpc_address\n", ip_str);
return false;
}

bool not_find_ip = true;
for (const auto &node : nodes) {
if (target_address == node.first) {
not_find_ip = false;
}
}

if (not_find_ip) {
err_info = fmt::format("invalid ip:port:{}, can't find it in metas \n", ip_str);
return false;
}

return true;
}
29 changes: 4 additions & 25 deletions src/shell/command_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,10 @@ inline bool validate_cmd(const argh::parser &cmd,
return true;
}

inline bool validate_ip(shell_context *sc,
const std::string &ip_str,
/*out*/ dsn::rpc_address &target_address,
/*out*/ std::string &err_info)
{
std::map<dsn::rpc_address, dsn::replication::node_status::type> nodes;
auto error = sc->ddl_client->list_nodes(::dsn::replication::node_status::NS_INVALID, nodes);
if (error != dsn::ERR_OK) {
err_info = fmt::format("list nodes failed, error={} \n", error.to_string());
return false;
}

bool not_find_ip = true;
for (const auto &node : nodes) {
if (ip_str == node.first.to_std_string()) {
target_address = node.first;
not_find_ip = false;
}
}
if (not_find_ip) {
err_info = fmt::format("invalid ip, error={} \n", ip_str);
return false;
}
return true;
}
bool validate_ip(shell_context *sc,
const std::string &ip_str,
/*out*/ dsn::rpc_address &target_address,
/*out*/ std::string &err_info);

#define verify_logged(exp, ...) \
do { \
Expand Down
6 changes: 3 additions & 3 deletions src/shell/commands/detect_hotkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ bool detect_hotkey(command_executor *e, shell_context *sc, arguments args)
}

dsn::rpc_address target_address;
std::string err_info;
std::string ip_str = cmd({"-d", "--address"}).str();
if (!target_address.from_string_ipv4(ip_str.c_str())) {
fmt::print("invalid ip, error={}\n", ip_str);
if (!validate_ip(sc, ip_str, target_address, err_info)) {
fmt::print("{}\n", err_info);
return false;
}

std::string err_info;
std::string hotkey_action = cmd({"-c", "--hotkey_action"}).str();
std::string hotkey_type = cmd({"-t", "--hotkey_type"}).str();
dsn::replication::detect_hotkey_request req;
Expand Down

0 comments on commit c0c39ca

Please sign in to comment.