This is an automated email from the ASF dual-hosted git repository. awong pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kudu.git
commit 5ce41d9075b04a39014ec8445b7cdf0cd2e64b10 Author: Andrew Wong <[email protected]> AuthorDate: Tue Oct 5 13:34:55 2021 -0700 [rpc] re-add methods_by_name() This patch reverts the removal of the methods_by_name() accessor method from patch 7f794e3ac8c389af4c74faeac11274e4ef0a55c0. Turns out it may be used outside the project, in the Apache Impala project[1]. To maintain consistency between the two projects, this re-adds the method. This patch also adds a simple test with this context to deter further removals of the call. [1] https://github.com/apache/impala/blob/b28da054f3595bb92873433211438306fc22fbc7/be/src/rpc/impala-service-pool.cc#L77 Change-Id: I2cbccdbbd119ebd53544d951e45b8bb4d34abae7 Reviewed-on: http://gerrit.cloudera.org:8080/17969 Reviewed-by: Alexey Serbin <[email protected]> Tested-by: Andrew Wong <[email protected]> --- src/kudu/rpc/rpc-test.cc | 10 ++++++++++ src/kudu/rpc/service_if.h | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/kudu/rpc/rpc-test.cc b/src/kudu/rpc/rpc-test.cc index bd7adf8..4a3aedd 100644 --- a/src/kudu/rpc/rpc-test.cc +++ b/src/kudu/rpc/rpc-test.cc @@ -48,6 +48,7 @@ #include "kudu/rpc/outbound_call.h" #include "kudu/rpc/proxy.h" #include "kudu/rpc/reactor.h" +#include "kudu/rpc/result_tracker.h" #include "kudu/rpc/rpc-test-base.h" #include "kudu/rpc/rpc_controller.h" #include "kudu/rpc/rpc_header.pb.h" @@ -1059,6 +1060,15 @@ static void AcceptAndReadForever(Socket* listen_sock) { } } +// Basic test for methods_by_name(). At the time of writing, this isn't used by +// Kudu, but is used in other projects like Apache Impala. +TEST_F(TestRpc, TestMethodsByName) { + std::unique_ptr<CalculatorService> service( + new CalculatorService(metric_entity_, result_tracker_)); + const auto& methods = service->methods_by_name(); + ASSERT_EQ(8, methods.size()); +} + // Starts a fake listening socket which never actually negotiates. // Ensures that the client gets a reasonable status code in this case. TEST_F(TestRpc, TestNegotiationTimeout) { diff --git a/src/kudu/rpc/service_if.h b/src/kudu/rpc/service_if.h index 71226db..185e291 100644 --- a/src/kudu/rpc/service_if.h +++ b/src/kudu/rpc/service_if.h @@ -114,6 +114,10 @@ class GeneratedServiceIf : public ServiceIf { RpcMethodInfo* LookupMethod(const RemoteMethod& method) override; + // Returns the mapping from method names to method infos. + typedef std::unordered_map<std::string, scoped_refptr<RpcMethodInfo>> MethodInfoMap; + const MethodInfoMap& methods_by_name() const { return methods_by_name_; } + protected: explicit GeneratedServiceIf(const scoped_refptr<ResultTracker>& tracker); @@ -124,7 +128,6 @@ class GeneratedServiceIf : public ServiceIf { // call. Methods are inserted by the constructor of the generated subclass. // After construction, this map is accessed by multiple threads and therefore // must not be modified. - typedef std::unordered_map<std::string, scoped_refptr<RpcMethodInfo>> MethodInfoMap; MethodInfoMap methods_by_name_; };
