dataroaring commented on code in PR #16617:
URL: https://github.com/apache/doris/pull/16617#discussion_r1122534473
##########
be/src/service/backend_options.cpp:
##########
@@ -101,6 +110,48 @@ bool BackendOptions::analyze_priority_cidrs() {
return true;
}
+bool BackendOptions::get_network_interfaces() {
+ if (config::network_interfaces == "") {
+ return true;
+ }
+ LOG(INFO) << "network name in conf: " << config::network_interfaces;
+
+ struct ifaddrs * ifAddrStruct = NULL;
+ void * tmpAddrPtr = NULL;
+
+ getifaddrs(&ifAddrStruct);
+
+ std::vector<std::string> name_strs =
+ strings::Split(config::network_interfaces,
PRIORITY_CIDR_SEPARATOR);
+ bool flag = false;
Review Comment:
found may be a better name here.
##########
be/src/service/backend_options.cpp:
##########
@@ -101,6 +110,48 @@ bool BackendOptions::analyze_priority_cidrs() {
return true;
}
+bool BackendOptions::get_network_interfaces() {
+ if (config::network_interfaces == "") {
+ return true;
+ }
+ LOG(INFO) << "network name in conf: " << config::network_interfaces;
+
+ struct ifaddrs * ifAddrStruct = NULL;
+ void * tmpAddrPtr = NULL;
+
+ getifaddrs(&ifAddrStruct);
+
+ std::vector<std::string> name_strs =
+ strings::Split(config::network_interfaces,
PRIORITY_CIDR_SEPARATOR);
+ bool flag = false;
+
+ for (auto& name_str : name_strs) {
+ while (ifAddrStruct!=NULL) {
+ if (ifAddrStruct->ifa_addr->sa_family==AF_INET) { // check it is
IP4
Review Comment:
we should put a space around !=, ==, +, - etc. liking while (ifAddrStruct
!= nullptr)
##########
be/src/service/backend_options.cpp:
##########
@@ -101,6 +110,48 @@ bool BackendOptions::analyze_priority_cidrs() {
return true;
}
+bool BackendOptions::get_network_interfaces() {
+ if (config::network_interfaces == "") {
+ return true;
+ }
+ LOG(INFO) << "network name in conf: " << config::network_interfaces;
+
+ struct ifaddrs * ifAddrStruct = NULL;
+ void * tmpAddrPtr = NULL;
+
+ getifaddrs(&ifAddrStruct);
+
+ std::vector<std::string> name_strs =
Review Comment:
nic_names is a better var name.
##########
be/src/service/backend_options.h:
##########
@@ -21,6 +21,8 @@
#include <string>
#include <vector>
+#include <ifaddrs.h>
+#include <arpa/inet.h>
Review Comment:
put the two .h to .cpp .
##########
be/src/service/backend_options.cpp:
##########
@@ -57,6 +62,10 @@ bool BackendOptions::init() {
VLOG_CRITICAL << "check ip=" << addr_it->get_host_address_v4();
if ((*addr_it).is_loopback_v4()) {
loopback = addr_it->get_host_address_v4();
+ } else if (!_s_net_interfaces.empty()) {
+ if (is_in_net_interface(addr_it->get_host_address_v4())) {
+ _s_localhost = addr_it->get_host_address_v4();
+ }
Review Comment:
We should not follow cidrs here.
There is a problem here, e.g. There are 2 nics, eth0 and eth1, we configed
eth1 and cidrs, if we tranverse eth0 first then cidr is used. we should let
network interface is selected in priority.
So we should handle net_interface before this while.
##########
be/src/service/backend_options.cpp:
##########
@@ -101,6 +110,48 @@ bool BackendOptions::analyze_priority_cidrs() {
return true;
}
+bool BackendOptions::get_network_interfaces() {
+ if (config::network_interfaces == "") {
+ return true;
+ }
+ LOG(INFO) << "network name in conf: " << config::network_interfaces;
+
+ struct ifaddrs * ifAddrStruct = NULL;
+ void * tmpAddrPtr = NULL;
+
+ getifaddrs(&ifAddrStruct);
+
+ std::vector<std::string> name_strs =
+ strings::Split(config::network_interfaces,
PRIORITY_CIDR_SEPARATOR);
+ bool flag = false;
+
+ for (auto& name_str : name_strs) {
+ while (ifAddrStruct!=NULL) {
+ if (ifAddrStruct->ifa_addr->sa_family==AF_INET) { // check it is
IP4
Review Comment:
for (; if_addr_struct != nullptr; if_addr_struct = if_addr_struct->ifa_next)
{
...
}
##########
be/src/service/backend_options.cpp:
##########
@@ -101,6 +110,48 @@ bool BackendOptions::analyze_priority_cidrs() {
return true;
}
+bool BackendOptions::get_network_interfaces() {
+ if (config::network_interfaces == "") {
+ return true;
+ }
+ LOG(INFO) << "network name in conf: " << config::network_interfaces;
Review Comment:
network interfaces in conf:
##########
be/src/service/backend_options.cpp:
##########
@@ -101,6 +110,48 @@ bool BackendOptions::analyze_priority_cidrs() {
return true;
}
+bool BackendOptions::get_network_interfaces() {
+ if (config::network_interfaces == "") {
+ return true;
+ }
+ LOG(INFO) << "network name in conf: " << config::network_interfaces;
+
+ struct ifaddrs * ifAddrStruct = NULL;
+ void * tmpAddrPtr = NULL;
+
+ getifaddrs(&ifAddrStruct);
+
+ std::vector<std::string> name_strs =
+ strings::Split(config::network_interfaces,
PRIORITY_CIDR_SEPARATOR);
+ bool flag = false;
+
+ for (auto& name_str : name_strs) {
+ while (ifAddrStruct!=NULL) {
+ if (ifAddrStruct->ifa_addr->sa_family==AF_INET) { // check it is
IP4
+ // is a valid IP4 Address
+ if (name_str == ifAddrStruct->ifa_name) {
+ tmpAddrPtr=&((struct sockaddr_in
*)ifAddrStruct->ifa_addr)->sin_addr;
Review Comment:
tmpAddrPtr = &...
##########
fe/fe-core/src/main/java/org/apache/doris/service/FrontendOptions.java:
##########
@@ -68,6 +81,11 @@ public static void init() throws UnknownHostException {
if (addr instanceof Inet4Address) {
if (addr.isLoopbackAddress()) {
loopBack = addr;
+ } else if (!netInterfaces.isEmpty()) {
+ if (isInNetInterface(addr.getHostAddress())) {
+ localAddr = addr;
+ break;
+ }
Review Comment:
same as be.
##########
be/src/service/backend_options.cpp:
##########
@@ -101,6 +110,48 @@ bool BackendOptions::analyze_priority_cidrs() {
return true;
}
+bool BackendOptions::get_network_interfaces() {
+ if (config::network_interfaces == "") {
+ return true;
+ }
+ LOG(INFO) << "network name in conf: " << config::network_interfaces;
+
+ struct ifaddrs * ifAddrStruct = NULL;
+ void * tmpAddrPtr = NULL;
+
+ getifaddrs(&ifAddrStruct);
+
+ std::vector<std::string> name_strs =
+ strings::Split(config::network_interfaces,
PRIORITY_CIDR_SEPARATOR);
+ bool flag = false;
+
+ for (auto& name_str : name_strs) {
+ while (ifAddrStruct!=NULL) {
+ if (ifAddrStruct->ifa_addr->sa_family==AF_INET) { // check it is
IP4
Review Comment:
use if_addr_struct instead of ifAddrStruct.
--
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]