From da0c0f0ac13ae4f6e867418756291940d9fa1636 Mon Sep 17 00:00:00 2001 From: cdjingit <642580887@qq.com> Date: Fri, 23 Dec 2022 17:26:56 +0800 Subject: [PATCH 1/3] optimize parallel channel request map method --- src/brpc/parallel_channel.cpp | 2 +- src/brpc/parallel_channel.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/brpc/parallel_channel.cpp b/src/brpc/parallel_channel.cpp index cf92e71097..ca71bedcc1 100644 --- a/src/brpc/parallel_channel.cpp +++ b/src/brpc/parallel_channel.cpp @@ -601,7 +601,7 @@ void ParallelChannel::CallMethod( for (int i = 0; i < nchan; ++i) { SubChan& sub_chan = _chans[i]; if (sub_chan.call_mapper != NULL) { - aps[i] = sub_chan.call_mapper->Map(i, method, request, response); + aps[i] = sub_chan.call_mapper->Map(i, nchan, method, request, response); // Test is_skip first because it implies is_bad. if (aps[i].is_skip()) { --ndone; diff --git a/src/brpc/parallel_channel.h b/src/brpc/parallel_channel.h index 8e82f600d6..562116dbfa 100644 --- a/src/brpc/parallel_channel.h +++ b/src/brpc/parallel_channel.h @@ -93,10 +93,20 @@ struct SubCall { // response->add_sub_response(), 0); class CallMapper : public SharedObject { public: + // TODO: Remove this backward compatibility method. virtual SubCall Map(int channel_index/*starting from 0*/, const google::protobuf::MethodDescriptor* method, const google::protobuf::Message* request, google::protobuf::Message* response) = 0; + + virtual SubCall Map(int channel_index/*starting from 0*/, + int channel_count, + const google::protobuf::MethodDescriptor* method, + const google::protobuf::Message* request, + google::protobuf::Message* response) { + return Map(channel_index, method, request, response); + } + protected: // Only callable by subclasses and butil::intrusive_ptr virtual ~CallMapper() {} From 7ca8f9fd79f278f298e4c28cc258b6b9b46593d7 Mon Sep 17 00:00:00 2001 From: cdjingit <642580887@qq.com> Date: Fri, 23 Dec 2022 17:53:17 +0800 Subject: [PATCH 2/3] optimize --- src/brpc/parallel_channel.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/brpc/parallel_channel.h b/src/brpc/parallel_channel.h index 562116dbfa..88c1b897c5 100644 --- a/src/brpc/parallel_channel.h +++ b/src/brpc/parallel_channel.h @@ -93,12 +93,6 @@ struct SubCall { // response->add_sub_response(), 0); class CallMapper : public SharedObject { public: - // TODO: Remove this backward compatibility method. - virtual SubCall Map(int channel_index/*starting from 0*/, - const google::protobuf::MethodDescriptor* method, - const google::protobuf::Message* request, - google::protobuf::Message* response) = 0; - virtual SubCall Map(int channel_index/*starting from 0*/, int channel_count, const google::protobuf::MethodDescriptor* method, @@ -108,6 +102,12 @@ class CallMapper : public SharedObject { } protected: + // TODO: Remove this backward compatibility method. + virtual SubCall Map(int channel_index/*starting from 0*/, + const google::protobuf::MethodDescriptor* method, + const google::protobuf::Message* request, + google::protobuf::Message* response) = 0; + // Only callable by subclasses and butil::intrusive_ptr virtual ~CallMapper() {} }; From 517a09e6d2f8a2708e060d7171d7cdf6a4d90262 Mon Sep 17 00:00:00 2001 From: cdjingit <642580887@qq.com> Date: Wed, 28 Dec 2022 14:38:31 +0800 Subject: [PATCH 3/3] optimze request map function --- src/brpc/parallel_channel.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/brpc/parallel_channel.h b/src/brpc/parallel_channel.h index 88c1b897c5..3ee8d58a9e 100644 --- a/src/brpc/parallel_channel.h +++ b/src/brpc/parallel_channel.h @@ -103,10 +103,13 @@ class CallMapper : public SharedObject { protected: // TODO: Remove this backward compatibility method. + // This method is deprecated. You should override public Map function. virtual SubCall Map(int channel_index/*starting from 0*/, const google::protobuf::MethodDescriptor* method, const google::protobuf::Message* request, - google::protobuf::Message* response) = 0; + google::protobuf::Message* response) { + return SubCall::Bad(); + } // Only callable by subclasses and butil::intrusive_ptr virtual ~CallMapper() {}