acelyc111 commented on a change in pull request #605: URL: https://github.com/apache/incubator-pegasus/pull/605#discussion_r496439746
########## File path: src/shell/commands/detect_hotkey.cpp ########## @@ -0,0 +1,131 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "shell/commands.h" +#include "shell/argh.h" +#include <dsn/dist/replication/replication_types.h> + +bool generate_hotkey_request(dsn::replication::detect_hotkey_request &req, + const std::string &hotkey_action, + const std::string &hotkey_type, + int app_id, + int partition_index, + std::string &err_info) +{ + if (!strcasecmp(hotkey_type.c_str(), "read")) { + req.type = dsn::replication::hotkey_type::type::READ; + } else if (!strcasecmp(hotkey_type.c_str(), "write")) { + req.type = dsn::replication::hotkey_type::type::WRITE; + } else { + err_info = fmt::format("\"{}\" is an invalid hotkey type (should be 'read' or 'write')\n", + hotkey_type); + return false; + } + + if (!strcasecmp(hotkey_action.c_str(), "start")) { + req.action = dsn::replication::detect_action::START; + } else if (!strcasecmp(hotkey_action.c_str(), "stop")) { + req.action = dsn::replication::detect_action::STOP; + } else { + err_info = + fmt::format("\"{}\" is an invalid hotkey detect action (should be 'start' or 'stop')\n", + hotkey_action); + return false; + } + req.pid = dsn::gpid(app_id, partition_index); + return true; +} + +// TODO: (Tangyanzhao) merge hotspot_partition_calculator::send_detect_hotkey_request +bool detect_hotkey(command_executor *e, shell_context *sc, arguments args) +{ + // detect_hotkey + // <-a|--app_id><-p|--partition_index><-c|--hotkey_action><-t|--hotkey_type><-d|--address> + const std::set<std::string> params = {"a", + "app_id", + "p", + "partition_index", + "c", + "hotkey_action", + "t", + "hotkey_type", + "d", + "address"}; + const std::set<std::string> flags = {}; + argh::parser cmd(args.argc, args.argv, argh::parser::PREFER_PARAM_FOR_UNREG_OPTION); + if (!validate_cmd(cmd, params, flags)) { + return false; + } + + int app_id; + if (!dsn::buf2int32(cmd({"-a", "--app_id"}).str(), app_id)) { + fmt::print( + stderr, + "\"{}\" is a invalid app_id, you should use `app` to check related information\n", Review comment: Update these logs, you only checked whether it's int type. ########## File path: src/shell/commands/detect_hotkey.cpp ########## @@ -0,0 +1,131 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "shell/commands.h" +#include "shell/argh.h" +#include <dsn/dist/replication/replication_types.h> + +bool generate_hotkey_request(dsn::replication::detect_hotkey_request &req, + const std::string &hotkey_action, + const std::string &hotkey_type, + int app_id, + int partition_index, + std::string &err_info) +{ + if (!strcasecmp(hotkey_type.c_str(), "read")) { + req.type = dsn::replication::hotkey_type::type::READ; + } else if (!strcasecmp(hotkey_type.c_str(), "write")) { + req.type = dsn::replication::hotkey_type::type::WRITE; + } else { + err_info = fmt::format("\"{}\" is an invalid hotkey type (should be 'read' or 'write')\n", + hotkey_type); + return false; + } + + if (!strcasecmp(hotkey_action.c_str(), "start")) { + req.action = dsn::replication::detect_action::START; + } else if (!strcasecmp(hotkey_action.c_str(), "stop")) { + req.action = dsn::replication::detect_action::STOP; + } else { + err_info = + fmt::format("\"{}\" is an invalid hotkey detect action (should be 'start' or 'stop')\n", + hotkey_action); + return false; + } + req.pid = dsn::gpid(app_id, partition_index); + return true; +} + +// TODO: (Tangyanzhao) merge hotspot_partition_calculator::send_detect_hotkey_request +bool detect_hotkey(command_executor *e, shell_context *sc, arguments args) +{ + // detect_hotkey + // <-a|--app_id><-p|--partition_index><-c|--hotkey_action><-t|--hotkey_type><-d|--address> + const std::set<std::string> params = {"a", + "app_id", + "p", + "partition_index", + "c", + "hotkey_action", + "t", + "hotkey_type", + "d", + "address"}; + const std::set<std::string> flags = {}; + argh::parser cmd(args.argc, args.argv, argh::parser::PREFER_PARAM_FOR_UNREG_OPTION); + if (!validate_cmd(cmd, params, flags)) { + return false; + } + + int app_id; + if (!dsn::buf2int32(cmd({"-a", "--app_id"}).str(), app_id)) { + fmt::print( + stderr, + "\"{}\" is a invalid app_id, you should use `app` to check related information\n", + cmd({"-a", "--app_id"}).str()); + return false; + } + + int partition_index; + if (!dsn::buf2int32(cmd({"-p", "--partition_index"}).str(), partition_index)) { + fmt::print(stderr, + "\"{}\" is a invalid partition index, you should use `app` to check related " Review comment: ```suggestion "\"{}\" is an invalid partition index, you should use `app` to check related " ``` ########## File path: src/shell/main.cpp ########## @@ -474,6 +474,16 @@ static command_executor commands[] = { "<-a --app_name str> [-f --forced]", cancel_bulk_load, }, + { + "detect_hotkey", + "start or stop hotkey detection on the replica", + "<-a|--app_id str> " Review comment: ```suggestion "<-a|--app_id num> " ``` ########## File path: src/shell/main.cpp ########## @@ -474,6 +474,16 @@ static command_executor commands[] = { "<-a --app_name str> [-f --forced]", cancel_bulk_load, }, + { + "detect_hotkey", + "start or stop hotkey detection on the replica", Review comment: ```suggestion "start or stop hotkey detection on a replica of a replica server", ``` ########## File path: src/shell/commands/detect_hotkey.cpp ########## @@ -0,0 +1,131 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "shell/commands.h" +#include "shell/argh.h" +#include <dsn/dist/replication/replication_types.h> + +bool generate_hotkey_request(dsn::replication::detect_hotkey_request &req, + const std::string &hotkey_action, + const std::string &hotkey_type, + int app_id, + int partition_index, + std::string &err_info) +{ + if (!strcasecmp(hotkey_type.c_str(), "read")) { + req.type = dsn::replication::hotkey_type::type::READ; + } else if (!strcasecmp(hotkey_type.c_str(), "write")) { + req.type = dsn::replication::hotkey_type::type::WRITE; + } else { + err_info = fmt::format("\"{}\" is an invalid hotkey type (should be 'read' or 'write')\n", + hotkey_type); + return false; + } + + if (!strcasecmp(hotkey_action.c_str(), "start")) { + req.action = dsn::replication::detect_action::START; + } else if (!strcasecmp(hotkey_action.c_str(), "stop")) { + req.action = dsn::replication::detect_action::STOP; + } else { + err_info = + fmt::format("\"{}\" is an invalid hotkey detect action (should be 'start' or 'stop')\n", + hotkey_action); + return false; + } + req.pid = dsn::gpid(app_id, partition_index); + return true; +} + +// TODO: (Tangyanzhao) merge hotspot_partition_calculator::send_detect_hotkey_request +bool detect_hotkey(command_executor *e, shell_context *sc, arguments args) +{ + // detect_hotkey + // <-a|--app_id><-p|--partition_index><-c|--hotkey_action><-t|--hotkey_type><-d|--address> + const std::set<std::string> params = {"a", + "app_id", + "p", + "partition_index", + "c", + "hotkey_action", + "t", + "hotkey_type", + "d", + "address"}; + const std::set<std::string> flags = {}; + argh::parser cmd(args.argc, args.argv, argh::parser::PREFER_PARAM_FOR_UNREG_OPTION); + if (!validate_cmd(cmd, params, flags)) { + return false; + } + + int app_id; + if (!dsn::buf2int32(cmd({"-a", "--app_id"}).str(), app_id)) { + fmt::print( + stderr, + "\"{}\" is a invalid app_id, you should use `app` to check related information\n", Review comment: ```suggestion "\"{}\" is an invalid app_id, you should use `app` to check related information\n", ``` ########## File path: src/shell/commands/detect_hotkey.cpp ########## @@ -0,0 +1,131 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "shell/commands.h" +#include "shell/argh.h" +#include <dsn/dist/replication/replication_types.h> + +bool generate_hotkey_request(dsn::replication::detect_hotkey_request &req, + const std::string &hotkey_action, + const std::string &hotkey_type, + int app_id, + int partition_index, + std::string &err_info) +{ + if (!strcasecmp(hotkey_type.c_str(), "read")) { + req.type = dsn::replication::hotkey_type::type::READ; + } else if (!strcasecmp(hotkey_type.c_str(), "write")) { + req.type = dsn::replication::hotkey_type::type::WRITE; + } else { + err_info = fmt::format("\"{}\" is an invalid hotkey type (should be 'read' or 'write')\n", + hotkey_type); + return false; + } + + if (!strcasecmp(hotkey_action.c_str(), "start")) { + req.action = dsn::replication::detect_action::START; + } else if (!strcasecmp(hotkey_action.c_str(), "stop")) { + req.action = dsn::replication::detect_action::STOP; + } else { + err_info = + fmt::format("\"{}\" is an invalid hotkey detect action (should be 'start' or 'stop')\n", + hotkey_action); + return false; + } + req.pid = dsn::gpid(app_id, partition_index); + return true; +} + +// TODO: (Tangyanzhao) merge hotspot_partition_calculator::send_detect_hotkey_request +bool detect_hotkey(command_executor *e, shell_context *sc, arguments args) +{ + // detect_hotkey + // <-a|--app_id><-p|--partition_index><-c|--hotkey_action><-t|--hotkey_type><-d|--address> + const std::set<std::string> params = {"a", + "app_id", + "p", + "partition_index", + "c", + "hotkey_action", + "t", + "hotkey_type", + "d", + "address"}; + const std::set<std::string> flags = {}; + argh::parser cmd(args.argc, args.argv, argh::parser::PREFER_PARAM_FOR_UNREG_OPTION); + if (!validate_cmd(cmd, params, flags)) { + return false; + } + + int app_id; + if (!dsn::buf2int32(cmd({"-a", "--app_id"}).str(), app_id)) { + fmt::print( + stderr, + "\"{}\" is a invalid app_id, you should use `app` to check related information\n", + cmd({"-a", "--app_id"}).str()); + return false; + } + + int partition_index; + if (!dsn::buf2int32(cmd({"-p", "--partition_index"}).str(), partition_index)) { + fmt::print(stderr, + "\"{}\" is a invalid partition index, you should use `app` to check related " + "information\n", + cmd({"-p", "--partition_index"}).str()); + return false; + } + + dsn::rpc_address target_address; + 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); Review comment: ```suggestion fmt::print("invalid ip, error={}\n", ip_str); ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
