morningman commented on code in PR #22454:
URL: https://github.com/apache/doris/pull/22454#discussion_r1283397124
##########
be/src/agent/heartbeat_server.cpp:
##########
@@ -118,14 +118,15 @@ Status HeartbeatServer::_heartbeat(const TMasterInfo&
master_info) {
if (!is_valid_ip(master_info.backend_ip)) {
//step2: resolve FQDN to IP
std::string ip;
- Status status = hostname_to_ip(master_info.backend_ip, ip);
+ Status status = hostname_to_ip(master_info.backend_ip, ip,
BackendOptions::is_bind_ipv6());
if (!status.ok()) {
std::stringstream ss;
ss << "can not get ip from fqdn: " << status.to_string();
LOG(WARNING) << ss.str();
return status;
}
-
+ LOG(INFO) << "master_info.backend_ip:" <<
master_info.backend_ip
Review Comment:
```suggestion
LOG(INFO) << "master_info.backend_ip: " <<
master_info.backend_ip
```
##########
be/src/agent/heartbeat_server.cpp:
##########
@@ -118,14 +118,15 @@ Status HeartbeatServer::_heartbeat(const TMasterInfo&
master_info) {
if (!is_valid_ip(master_info.backend_ip)) {
//step2: resolve FQDN to IP
std::string ip;
- Status status = hostname_to_ip(master_info.backend_ip, ip);
+ Status status = hostname_to_ip(master_info.backend_ip, ip,
BackendOptions::is_bind_ipv6());
if (!status.ok()) {
std::stringstream ss;
ss << "can not get ip from fqdn: " << status.to_string();
LOG(WARNING) << ss.str();
return status;
}
-
+ LOG(INFO) << "master_info.backend_ip:" <<
master_info.backend_ip
+ << ",hostname_to_ip:" << ip;
Review Comment:
```suggestion
<< ", hostname_to_ip:" << ip;
```
##########
be/src/util/network_util.cpp:
##########
@@ -72,70 +72,35 @@ Status get_hostname(std::string* hostname) {
return Status::OK();
}
-Status hostname_to_ip_addrs(const std::string& name, std::vector<std::string>*
addresses) {
- addrinfo hints;
- memset(&hints, 0, sizeof(struct addrinfo));
- hints.ai_family = AF_INET; // IPv4 addresses only
- hints.ai_socktype = SOCK_STREAM;
-
- struct addrinfo* addr_info;
-
- if (getaddrinfo(name.c_str(), nullptr, &hints, &addr_info) != 0) {
- return Status::InternalError("Could not find IPv4 address for: {}",
name);
- }
-
- addrinfo* it = addr_info;
-
- while (it != nullptr) {
- char addr_buf[64];
- const char* result =
- inet_ntop(AF_INET, &((sockaddr_in*)it->ai_addr)->sin_addr,
addr_buf, 64);
-
- if (result == nullptr) {
- freeaddrinfo(addr_info);
- return Status::InternalError("Could not convert IPv4 address for:
{}", name);
- }
-
- // add address if not exists
- std::string address = std::string(addr_buf);
- if (std::find(addresses->begin(), addresses->end(), address) !=
addresses->end()) {
- LOG(WARNING) << "Repeated ip addresses has been found for host: "
<< name
- << ", ip address:" << address
- << ", please check your network configuration";
- } else {
- addresses->push_back(address);
- }
- it = it->ai_next;
- }
-
- freeaddrinfo(addr_info);
- return Status::OK();
-}
-
bool is_valid_ip(const std::string& ip) {
unsigned char buf[sizeof(struct in6_addr)];
return (inet_pton(AF_INET6, ip.data(), buf) > 0) || (inet_pton(AF_INET,
ip.data(), buf) > 0);
}
Status hostname_to_ip(const std::string& host, std::string& ip) {
- std::vector<std::string> addresses;
- Status status = hostname_to_ip_addrs(host, &addresses);
- if (!status.ok()) {
- LOG(WARNING) << "status of hostname_to_ip_addrs was not ok, err is "
<< status.to_string();
+ Status status = hostname_to_ip(host, ip, false);
+ if (status.ok()) {
return status;
}
- if (addresses.size() != 1) {
- std::stringstream ss;
- std::copy(addresses.begin(), addresses.end(),
std::ostream_iterator<std::string>(ss, ","));
- LOG(WARNING)
- << "the number of addresses could only be equal to 1, failed
to get ip from host:"
- << host << ", addresses:" << ss.str();
- return Status::InternalError(
- "the number of addresses could only be equal to 1, failed to
get ip from host: "
- "{}, addresses:{}",
- host, ss.str());
+ return hostname_to_ip(host, ip, true);
+}
+
+Status hostname_to_ip(const std::string& host, std::string& ip, bool ipv6) {
+ int __af = ipv6 ? AF_INET6 : AF_INET;
+ struct hostent* pstHostent = NULL;
+ if (inet_addr(host.c_str()) == INADDR_NONE) {
+ if ((pstHostent = gethostbyname2(host.c_str(), __af)) == NULL) {
Review Comment:
The `gethostbyname2` is deprecated:
https://refspecs.linuxbase.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/baselib-gethostbyname2-3.html
--
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]