From 1fe7bce236d6a7058ea6baf84d3fce62f2cc52ed Mon Sep 17 00:00:00 2001 From: ehds Date: Thu, 29 Sep 2022 20:34:25 +0800 Subject: [PATCH 1/5] fix(rpc_replay) continue when failed to init channel --- tools/rpc_replay/rpc_replay.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/rpc_replay/rpc_replay.cpp b/tools/rpc_replay/rpc_replay.cpp index a08fbefa1c..84d2fb14a0 100644 --- a/tools/rpc_replay/rpc_replay.cpp +++ b/tools/rpc_replay/rpc_replay.cpp @@ -93,8 +93,8 @@ int ChannelGroup::Init() { options.max_retry = FLAGS_max_retry; if (chan->Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(), &options) != 0) { - LOG(ERROR) << "Fail to initialize channel"; - return -1; + LOG(WARNING) << "Fail to initialize channel"; + continue; } _chans[prot] = chan; } From 9e4ead3905e539da7a6687e1dcce963ab89b257c Mon Sep 17 00:00:00 2001 From: ehds Date: Fri, 30 Sep 2022 18:03:41 +0800 Subject: [PATCH 2/5] check supported_connection_type --- tools/rpc_replay/rpc_replay.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/rpc_replay/rpc_replay.cpp b/tools/rpc_replay/rpc_replay.cpp index 84d2fb14a0..6f30bb4573 100644 --- a/tools/rpc_replay/rpc_replay.cpp +++ b/tools/rpc_replay/rpc_replay.cpp @@ -83,7 +83,9 @@ int ChannelGroup::Init() { _chans.resize(max_protocol_size + 1); for (size_t i = 0; i < protocols.size(); ++i) { if (protocols[i].second.support_client() && - protocols[i].second.support_server()) { + protocols[i].second.support_server() && + (brpc::StringToConnectionType(FLAGS_connection_type) & + protocols[i].second.supported_connection_type)) { const brpc::ProtocolType prot = protocols[i].first; brpc::Channel* chan = new brpc::Channel; brpc::ChannelOptions options; @@ -93,8 +95,8 @@ int ChannelGroup::Init() { options.max_retry = FLAGS_max_retry; if (chan->Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(), &options) != 0) { - LOG(WARNING) << "Fail to initialize channel"; - continue; + LOG(ERROR) << "Fail to initialize channel"; + return -1; } _chans[prot] = chan; } From 39ec6a62f04258b72712313e8ebe0210d82523e8 Mon Sep 17 00:00:00 2001 From: ehds Date: Fri, 30 Sep 2022 22:43:27 +0800 Subject: [PATCH 3/5] check supported_connection_type --- tools/rpc_replay/rpc_replay.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tools/rpc_replay/rpc_replay.cpp b/tools/rpc_replay/rpc_replay.cpp index 6f30bb4573..5e293785dd 100644 --- a/tools/rpc_replay/rpc_replay.cpp +++ b/tools/rpc_replay/rpc_replay.cpp @@ -29,6 +29,9 @@ #include #include #include +#include "brpc/adaptive_connection_type.h" +#include "brpc/adaptive_protocol_type.h" +#include "brpc/options.pb.h" #include "info_thread.h" DEFINE_string(dir, "", "The directory of dumped requests"); @@ -83,16 +86,21 @@ int ChannelGroup::Init() { _chans.resize(max_protocol_size + 1); for (size_t i = 0; i < protocols.size(); ++i) { if (protocols[i].second.support_client() && - protocols[i].second.support_server() && - (brpc::StringToConnectionType(FLAGS_connection_type) & - protocols[i].second.supported_connection_type)) { + protocols[i].second.support_server()) { const brpc::ProtocolType prot = protocols[i].first; - brpc::Channel* chan = new brpc::Channel; brpc::ChannelOptions options; options.protocol = prot; options.connection_type = FLAGS_connection_type; options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/; options.max_retry = FLAGS_max_retry; + if (options.connection_type != brpc::CONNECTION_TYPE_UNKNOWN && + !(options.connection_type & + protocols[i].second.supported_connection_type)) { + // If protoctol does not support user specified connection type, + // skip to init channel. + continue; + } + brpc::Channel* chan = new brpc::Channel; if (chan->Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(), &options) != 0) { LOG(ERROR) << "Fail to initialize channel"; From f64ed714f9129462c250b826a5be504a3f25d83d Mon Sep 17 00:00:00 2001 From: ehds Date: Sat, 1 Oct 2022 10:57:07 +0800 Subject: [PATCH 4/5] check supported_connection_type --- tools/rpc_replay/rpc_replay.cpp | 42 +++++++++++++++------------------ 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/tools/rpc_replay/rpc_replay.cpp b/tools/rpc_replay/rpc_replay.cpp index 5e293785dd..c64ee040f5 100644 --- a/tools/rpc_replay/rpc_replay.cpp +++ b/tools/rpc_replay/rpc_replay.cpp @@ -85,28 +85,24 @@ int ChannelGroup::Init() { } _chans.resize(max_protocol_size + 1); for (size_t i = 0; i < protocols.size(); ++i) { - if (protocols[i].second.support_client() && - protocols[i].second.support_server()) { - const brpc::ProtocolType prot = protocols[i].first; - brpc::ChannelOptions options; - options.protocol = prot; - options.connection_type = FLAGS_connection_type; - options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/; - options.max_retry = FLAGS_max_retry; - if (options.connection_type != brpc::CONNECTION_TYPE_UNKNOWN && - !(options.connection_type & - protocols[i].second.supported_connection_type)) { - // If protoctol does not support user specified connection type, - // skip to init channel. - continue; - } - brpc::Channel* chan = new brpc::Channel; - if (chan->Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(), - &options) != 0) { - LOG(ERROR) << "Fail to initialize channel"; - return -1; - } - _chans[prot] = chan; + const brpc::ProtocolType protocol_type = protocols[i].first; + const brpc::Protocol protocol = protocols[i].second; + brpc::ChannelOptions options; + options.protocol = protocol_type;; + options.connection_type = FLAGS_connection_type; + options.timeout_ms = FLAGS_timeout_ms /*milliseconds*/; + options.max_retry = FLAGS_max_retry; + if ((options.connection_type == brpc::CONNECTION_TYPE_UNKNOWN || + (options.connection_type & protocol.supported_connection_type)) && + protocol.support_client() && protocol.support_server()) { + brpc::Channel *chan = new brpc::Channel; + if (chan->Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(), + &options) != 0) { + LOG(ERROR) << "Fail to initialize channel"; + delete chan; + return -1; + } + _chans[protocol_type] = chan; } } return 0; @@ -259,7 +255,7 @@ int main(int argc, char* argv[]) { if (req_rate_per_thread > rate_limit_per_thread) { LOG(ERROR) << "req_rate: " << (int64_t) req_rate_per_thread << " is too large in one thread. The rate limit is " << rate_limit_per_thread << " in one thread"; - return false; + return -1; } std::vector bids; From 6f2c65aeae4ea1a8459c53ba53439d9f32ac74d7 Mon Sep 17 00:00:00 2001 From: ehds Date: Sat, 1 Oct 2022 11:09:39 +0800 Subject: [PATCH 5/5] fix lint --- tools/rpc_replay/rpc_replay.cpp | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/tools/rpc_replay/rpc_replay.cpp b/tools/rpc_replay/rpc_replay.cpp index c64ee040f5..412397b29c 100644 --- a/tools/rpc_replay/rpc_replay.cpp +++ b/tools/rpc_replay/rpc_replay.cpp @@ -29,8 +29,6 @@ #include #include #include -#include "brpc/adaptive_connection_type.h" -#include "brpc/adaptive_protocol_type.h" #include "brpc/options.pb.h" #include "info_thread.h" @@ -88,21 +86,22 @@ int ChannelGroup::Init() { const brpc::ProtocolType protocol_type = protocols[i].first; const brpc::Protocol protocol = protocols[i].second; brpc::ChannelOptions options; - options.protocol = protocol_type;; + options.protocol = protocol_type; options.connection_type = FLAGS_connection_type; - options.timeout_ms = FLAGS_timeout_ms /*milliseconds*/; + options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/; options.max_retry = FLAGS_max_retry; - if ((options.connection_type == brpc::CONNECTION_TYPE_UNKNOWN || - (options.connection_type & protocol.supported_connection_type)) && - protocol.support_client() && protocol.support_server()) { - brpc::Channel *chan = new brpc::Channel; - if (chan->Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(), - &options) != 0) { - LOG(ERROR) << "Fail to initialize channel"; - delete chan; - return -1; - } - _chans[protocol_type] = chan; + if ((options.connection_type == brpc::CONNECTION_TYPE_UNKNOWN || + options.connection_type & protocol.supported_connection_type) && + protocol.support_client() && + protocol.support_server()) { + brpc::Channel* chan = new brpc::Channel; + if (chan->Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(), + &options) != 0) { + LOG(ERROR) << "Fail to initialize channel"; + delete chan; + return -1; + } + _chans[protocol_type] = chan; } } return 0; @@ -255,7 +254,7 @@ int main(int argc, char* argv[]) { if (req_rate_per_thread > rate_limit_per_thread) { LOG(ERROR) << "req_rate: " << (int64_t) req_rate_per_thread << " is too large in one thread. The rate limit is " << rate_limit_per_thread << " in one thread"; - return -1; + return false; } std::vector bids;