From 57bd3d6fef0047850acc7a1b963324405bd57a30 Mon Sep 17 00:00:00 2001 From: lianxuechao Date: Mon, 2 Dec 2024 11:38:59 +0800 Subject: [PATCH] rm useless methods and refactor getter/setter --- docs/cn/server.md | 2 -- docs/en/server.md | 2 -- src/brpc/baidu_master_service.cpp | 2 +- src/brpc/baidu_master_service.h | 10 ++++-- src/brpc/server.cpp | 54 ++++++------------------------- src/brpc/server.h | 12 ------- 6 files changed, 17 insertions(+), 65 deletions(-) diff --git a/docs/cn/server.md b/docs/cn/server.md index 9343a24832..0e68c51d40 100644 --- a/docs/cn/server.md +++ b/docs/cn/server.md @@ -1067,8 +1067,6 @@ server.IgnoreEovercrowdedOf("...") = ...可设置method级别的ignore_eovercrow ```c++ ServerOptions.ignore_eovercrowded = true; // Set the default ignore_eovercrowded for all methods server.IgnoreEovercrowdedOf("example.EchoService.Echo") = true; -server.IgnoreEovercrowdedOf("example.EchoService", "Echo") = true; -server.IgnoreEovercrowdedOf(&service, "Echo") = true; ``` 此设置一般**发生在AddService后,server启动前**。当设置失败时(比如对应的method不存在),server会启动失败同时提示用户修正IgnoreEovercrowdedOf设置错误。 diff --git a/docs/en/server.md b/docs/en/server.md index 3e26b58266..e49f8512ae 100644 --- a/docs/en/server.md +++ b/docs/en/server.md @@ -1063,8 +1063,6 @@ server.IgnoreEovercrowdedOf("...") = … sets ignore_eovercrowded of the method. ```c++ ServerOptions.ignore_eovercrowded = true; // Set the default ignore_eovercrowded for all methods server.IgnoreEovercrowdedOf("example.EchoService.Echo") = true; -server.IgnoreEovercrowdedOf("example.EchoService", "Echo") = true; -server.IgnoreEovercrowdedOf(&service, "Echo") = true; ``` The code is generally put **after AddService, before Start() of the server**. When a setting fails(namely the method does not exist), server will fail to start and notify user to fix settings on IgnoreEovercrowdedOf. diff --git a/src/brpc/baidu_master_service.cpp b/src/brpc/baidu_master_service.cpp index 11083c2482..b1b0fa0dbf 100644 --- a/src/brpc/baidu_master_service.cpp +++ b/src/brpc/baidu_master_service.cpp @@ -22,7 +22,7 @@ namespace brpc { BaiduMasterService::BaiduMasterService() - : _status(new (std::nothrow) MethodStatus), ignore_eovercrowded(false) { + : _status(new (std::nothrow) MethodStatus), _ignore_eovercrowded(false) { LOG_IF(FATAL, NULL == _status) << "Fail to new MethodStatus"; } diff --git a/src/brpc/baidu_master_service.h b/src/brpc/baidu_master_service.h index 1747f06153..11846fd9b4 100644 --- a/src/brpc/baidu_master_service.h +++ b/src/brpc/baidu_master_service.h @@ -45,8 +45,12 @@ class BaiduMasterService : public ::google::protobuf::Service return _max_concurrency; } - bool& IgnoreEOverCrowded() { - return ignore_eovercrowded; + bool ignore_eovercrowded() { + return _ignore_eovercrowded; + } + + void set_ignore_eovercrowded(bool ignore_eovercrowded) { + _ignore_eovercrowded = ignore_eovercrowded; } virtual void ProcessRpcRequest(Controller* cntl, @@ -96,7 +100,7 @@ friend class Server; MethodStatus* _status; AdaptiveMaxConcurrency _max_concurrency; - bool ignore_eovercrowded; + bool _ignore_eovercrowded; }; } diff --git a/src/brpc/server.cpp b/src/brpc/server.cpp index f557d1870c..e904e6c8af 100644 --- a/src/brpc/server.cpp +++ b/src/brpc/server.cpp @@ -2311,7 +2311,13 @@ int Server::MaxConcurrencyOf(google::protobuf::Service* service, return MaxConcurrencyOf(service->GetDescriptor()->full_name(), method_name); } -bool& Server::IgnoreEovercrowdedOf(MethodProperty* mp) { +bool& Server::IgnoreEovercrowdedOf(const butil::StringPiece& full_method_name) { + MethodProperty* mp = _method_map.seek(full_method_name); + if (mp == NULL) { + LOG(ERROR) << "Fail to find method=" << full_method_name; + _failed_to_set_ignore_eovercrowded = true; + return g_default_ignore_eovercrowded; + } if (IsRunning()) { LOG(WARNING) << "IgnoreEovercrowdedOf is only allowd before Server started"; return g_default_ignore_eovercrowded; @@ -2325,7 +2331,8 @@ bool& Server::IgnoreEovercrowdedOf(MethodProperty* mp) { return mp->ignore_eovercrowded; } -bool Server::IgnoreEovercrowdedOf(const MethodProperty* mp) const { +bool Server::IgnoreEovercrowdedOf(const butil::StringPiece& full_method_name) const { + MethodProperty* mp = _method_map.seek(full_method_name); if (IsRunning()) { LOG(WARNING) << "IgnoreEovercrowdedOf is only allowd before Server started"; return g_default_ignore_eovercrowded; @@ -2336,49 +2343,6 @@ bool Server::IgnoreEovercrowdedOf(const MethodProperty* mp) const { return mp->ignore_eovercrowded; } -bool& Server::IgnoreEovercrowdedOf(const butil::StringPiece& full_method_name) { - MethodProperty* mp = _method_map.seek(full_method_name); - if (mp == NULL) { - LOG(ERROR) << "Fail to find method=" << full_method_name; - _failed_to_set_ignore_eovercrowded = true; - return g_default_ignore_eovercrowded; - } - return IgnoreEovercrowdedOf(mp); -} - -bool Server::IgnoreEovercrowdedOf(const butil::StringPiece& full_method_name) const { - return IgnoreEovercrowdedOf(_method_map.seek(full_method_name)); -} - -bool& Server::IgnoreEovercrowdedOf(const butil::StringPiece& full_service_name, - const butil::StringPiece& method_name) { - MethodProperty* mp = const_cast( - FindMethodPropertyByFullName(full_service_name, method_name)); - if (mp == NULL) { - LOG(ERROR) << "Fail to find method=" << full_service_name - << '/' << method_name; - _failed_to_set_ignore_eovercrowded = true; - return g_default_ignore_eovercrowded; - } - return IgnoreEovercrowdedOf(mp); -} - -bool Server::IgnoreEovercrowdedOf(const butil::StringPiece& full_service_name, - const butil::StringPiece& method_name) const { - return IgnoreEovercrowdedOf(FindMethodPropertyByFullName( - full_service_name, method_name)); -} - -bool& Server::IgnoreEovercrowdedOf(google::protobuf::Service* service, - const butil::StringPiece& method_name) { - return IgnoreEovercrowdedOf(service->GetDescriptor()->full_name(), method_name); -} - -bool Server::IgnoreEovercrowdedOf(google::protobuf::Service* service, - const butil::StringPiece& method_name) const { - return IgnoreEovercrowdedOf(service->GetDescriptor()->full_name(), method_name); -} - bool Server::AcceptRequest(Controller* cntl) const { const Interceptor* interceptor = _options.interceptor; if (!interceptor) { diff --git a/src/brpc/server.h b/src/brpc/server.h index d609b4d85a..8d1b093cc7 100644 --- a/src/brpc/server.h +++ b/src/brpc/server.h @@ -604,16 +604,6 @@ class Server { bool& IgnoreEovercrowdedOf(const butil::StringPiece& full_method_name); bool IgnoreEovercrowdedOf(const butil::StringPiece& full_method_name) const; - bool& IgnoreEovercrowdedOf(const butil::StringPiece& full_service_name, - const butil::StringPiece& method_name); - bool IgnoreEovercrowdedOf(const butil::StringPiece& full_service_name, - const butil::StringPiece& method_name) const; - - bool& IgnoreEovercrowdedOf(google::protobuf::Service* service, - const butil::StringPiece& method_name); - bool IgnoreEovercrowdedOf(google::protobuf::Service* service, - const butil::StringPiece& method_name) const; - int Concurrency() const { return butil::subtle::NoBarrier_Load(&_concurrency); }; @@ -718,8 +708,6 @@ friend class Controller; AdaptiveMaxConcurrency& MaxConcurrencyOf(MethodProperty*); int MaxConcurrencyOf(const MethodProperty*) const; - bool& IgnoreEovercrowdedOf(MethodProperty*); - bool IgnoreEovercrowdedOf(const MethodProperty*) const; static bool CreateConcurrencyLimiter(const AdaptiveMaxConcurrency& amc, ConcurrencyLimiter** out);