Skip to content

Commit

Permalink
rm useless methods and refactor getter/setter
Browse files Browse the repository at this point in the history
  • Loading branch information
lianxuechao committed Dec 2, 2024
1 parent a4c4ba1 commit 57bd3d6
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 65 deletions.
2 changes: 0 additions & 2 deletions docs/cn/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -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设置错误。
Expand Down
2 changes: 0 additions & 2 deletions docs/en/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/brpc/baidu_master_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

Expand Down
10 changes: 7 additions & 3 deletions src/brpc/baidu_master_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -96,7 +100,7 @@ friend class Server;

MethodStatus* _status;
AdaptiveMaxConcurrency _max_concurrency;
bool ignore_eovercrowded;
bool _ignore_eovercrowded;
};

}
Expand Down
54 changes: 9 additions & 45 deletions src/brpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<MethodProperty*>(
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) {
Expand Down
12 changes: 0 additions & 12 deletions src/brpc/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 57bd3d6

Please sign in to comment.