empiredan commented on code in PR #1894:
URL:
https://github.com/apache/incubator-pegasus/pull/1894#discussion_r1477680305
##########
src/runtime/rpc/rpc_host_port.cpp:
##########
@@ -40,46 +42,55 @@ const host_port host_port::s_invalid_host_port;
host_port::host_port(std::string host, uint16_t port)
: _host(std::move(host)), _port(port), _type(HOST_TYPE_IPV4)
{
- CHECK_NE_MSG(rpc_address::ipv4_from_host(_host.c_str()), 0, "invalid
hostname: {}", _host);
+ // ipv4_from_host may be slow, just call it in DEBUG version.
+ DCHECK_NE_MSG(rpc_address::ipv4_from_host(_host.c_str()), 0, "invalid
hostname: {}", _host);
}
-host_port::host_port(rpc_address addr)
+host_port host_port::from_address(rpc_address addr)
{
+ host_port hp;
+ SCOPED_LOG_SLOW_EXECUTION(
+ WARNING, 100, "construct host_port '{}' from rpc_address '{}'", hp,
addr);
switch (addr.type()) {
case HOST_TYPE_IPV4: {
- CHECK(utils::hostname_from_ip(htonl(addr.ip()), &_host),
+ CHECK(utils::hostname_from_ip(htonl(addr.ip()), &hp._host),
"invalid host_port {}",
addr.ipv4_str());
- _port = addr.port();
+ hp._port = addr.port();
} break;
case HOST_TYPE_GROUP: {
- _group_host_port =
std::make_shared<rpc_group_host_port>(addr.group_address());
+ hp._group_host_port =
std::make_shared<rpc_group_host_port>(addr.group_address());
} break;
default:
break;
}
- _type = addr.type();
+ hp._type = addr.type();
+ return hp;
}
-bool host_port::from_string(const std::string &s)
+host_port host_port::from_string(const std::string &host_port_str)
{
- const auto pos = s.find_last_of(':');
+ host_port hp;
+ SCOPED_LOG_SLOW_EXECUTION(
+ WARNING, 100, "construct host_port '{}' from string '{}'", hp,
host_port_str);
+ const auto pos = host_port_str.find_last_of(':');
if (dsn_unlikely(pos == std::string::npos)) {
- return false;
+ return hp;
}
- _host = s.substr(0, pos);
- std::string port = s.substr(pos + 1);
- if (dsn_unlikely(!dsn::buf2uint16(port, _port))) {
- return false;
+ hp._host = host_port_str.substr(0, pos);
+ const auto port_str = host_port_str.substr(pos + 1);
+ if (dsn_unlikely(!dsn::buf2uint16(port_str, hp._port))) {
+ return hp;
}
- if (dsn_unlikely(rpc_address::ipv4_from_host(_host.c_str()) == 0)) {
- return false;
+ if (dsn_unlikely(rpc_address::ipv4_from_host(hp._host.c_str()) == 0)) {
+ return hp;
}
- _type = HOST_TYPE_IPV4;
- return true;
+ // Now is_invalid() return true.
Review Comment:
```suggestion
// Now is_invalid() return false.
```
##########
src/common/json_helper.h:
##########
@@ -436,7 +436,8 @@ inline bool json_decode(const dsn::json::JsonObject &in,
dsn::host_port &hp)
if (host_port_string == "invalid host_port") {
return true;
}
- return hp.from_string(host_port_string);
+ hp = host_port::from_string(host_port_string);
+ return hp.is_invalid();
Review Comment:
```suggestion
return !hp.is_invalid();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]