-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature](network interface) Support network interface #16617
Conversation
clang-tidy review says "All clean, LGTM! 👍" |
title style : |
be/src/service/backend_options.cpp
Outdated
LOG(INFO) << "priority cidrs in conf: " << config::priority_networks; | ||
|
||
// 解析IP为cidr表达方式 | ||
bool BackendOptions::analyze_cidrs(const std::string & ip) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to modify this function.
be/src/service/backend_options.cpp
Outdated
} | ||
LOG(INFO) << "priority cidrs in conf: " << config::priority_networks; | ||
|
||
// 解析IP为cidr表达方式 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use english comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change your PR title format.
be/src/service/backend_options.cpp
Outdated
@@ -101,6 +100,61 @@ bool BackendOptions::analyze_priority_cidrs() { | |||
return true; | |||
} | |||
|
|||
|
|||
//从network_interface中获取IP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
be/src/service/backend_options.cpp
Outdated
// } | ||
// _s_priority_cidrs.push_back(cidr); | ||
// } | ||
// return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useless code?
// _s_priority_cidrs.push_back(cidr); | ||
// } | ||
// return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
conf/be.conf
Outdated
|
||
# data root path, separate by ';' | ||
# you can specify the storage medium of each root path, HDD or SSD | ||
# you can add capacity limit at the end of each root path, separate by ',' | ||
# eg: | ||
# storage_root_path = /home/disk1/doris.HDD,50;/home/disk2/doris.SSD,1;/home/disk2/doris | ||
# storage_root_path = /root/git/output/be/storage;/home/disk2/doris.SSD,1;/home/disk2/doris | ||
# /home/disk1/doris.HDD, capacity limit is 50GB, HDD; | ||
# /home/disk2/doris.SSD, capacity limit is 1GB, SSD; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modify this file in your environment, but do not commit it.
@@ -52,7 +52,7 @@ mysql_service_nio_enabled = true | |||
# If no ip match this rule, will choose one randomly. | |||
# use CIDR format, e.g. 10.10.10.0/24 | |||
# Default value is empty. | |||
# priority_networks = 10.10.10.0/24;192.168.0.0/16 | |||
priority_networks = 127.0.0.1/16 | |||
|
|||
# Advanced configurations | |||
# log_roll_size_mb = 1024 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
clang-tidy review says "All clean, LGTM! 👍" |
Please amend your PR title and add describe in your PR comment. |
be/src/common/config.h
Outdated
@@ -49,6 +49,8 @@ CONF_Int32(single_replica_load_brpc_num_threads, "64"); | |||
// If no ip match this rule, will choose one randomly. | |||
CONF_String(priority_networks, ""); | |||
|
|||
CONF_Strings(network_interface, ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String is enough.
be/src/service/backend_options.cpp
Outdated
return false; | ||
} | ||
LOG(INFO) << "network name in conf: " << config::network_interface[0] << "\tpriority cidrs in conf: " << config::network_interface[1]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should not print cidrs here, it is confusing.
be/src/service/backend_options.cpp
Outdated
} | ||
LOG(INFO) << "network name in conf: " << config::network_interface[0] << "\tpriority cidrs in conf: " << config::network_interface[1]; | ||
|
||
std::vector<std::string> cidr_strs = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variable name is confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
be/src/service/backend_options.cpp
Outdated
} | ||
LOG(INFO) << "network name in conf: " << config::network_interfaces; | ||
|
||
struct ifaddrs * ifAddrStruct = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: use nullptr [modernize-use-nullptr]
struct ifaddrs * ifAddrStruct = NULL; | |
struct ifaddrs * ifAddrStruct = nullptr; |
be/src/service/backend_options.cpp
Outdated
LOG(INFO) << "network name in conf: " << config::network_interfaces; | ||
|
||
struct ifaddrs * ifAddrStruct = NULL; | ||
void * tmpAddrPtr = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: use nullptr [modernize-use-nullptr]
void * tmpAddrPtr = NULL; | |
void * tmpAddrPtr = nullptr; |
be/src/service/backend_options.cpp
Outdated
bool flag = false; | ||
|
||
for (auto& name_str : name_strs) { | ||
while (ifAddrStruct!=NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: use nullptr [modernize-use-nullptr]
while (ifAddrStruct!=NULL) { | |
while (ifAddrStruct!=nullptr) { |
be/src/service/backend_options.cpp
Outdated
if (config::network_interfaces == "") { | ||
return true; | ||
} | ||
LOG(INFO) << "network name in conf: " << config::network_interfaces; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
network interfaces in conf:
|
||
std::vector<std::string> name_strs = | ||
strings::Split(config::network_interfaces, PRIORITY_CIDR_SEPARATOR); | ||
bool flag = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
found may be a better name here.
be/src/service/backend_options.cpp
Outdated
|
||
getifaddrs(&ifAddrStruct); | ||
|
||
std::vector<std::string> name_strs = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nic_names is a better var name.
be/src/service/backend_options.cpp
Outdated
|
||
for (auto& name_str : name_strs) { | ||
while (ifAddrStruct!=NULL) { | ||
if (ifAddrStruct->ifa_addr->sa_family==AF_INET) { // check it is IP4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should put a space around !=, ==, +, - etc. liking while (ifAddrStruct != nullptr)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (; if_addr_struct != nullptr; if_addr_struct = if_addr_struct->ifa_next) {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use if_addr_struct instead of ifAddrStruct.
be/src/service/backend_options.cpp
Outdated
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tmpAddrPtr = &...
be/src/service/backend_options.cpp
Outdated
} 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(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.h
Outdated
@@ -21,6 +21,8 @@ | |||
|
|||
#include <string> | |||
#include <vector> | |||
#include <ifaddrs.h> | |||
#include <arpa/inet.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put the two .h to .cpp .
if (isInNetInterface(addr.getHostAddress())) { | ||
localAddr = addr; | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please have a look at the comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
be/src/service/backend_options.cpp
Outdated
} | ||
LOG(INFO) << "network interfaces in conf: " << config::network_interfaces; | ||
|
||
struct ifaddrs * if_Addr_Struct = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: use nullptr [modernize-use-nullptr]
struct ifaddrs * if_Addr_Struct = NULL; | |
struct ifaddrs * if_Addr_Struct = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
be/src/service/backend_options.cpp
Outdated
} | ||
LOG(INFO) << "network interfaces in conf: " << config::network_interfaces; | ||
|
||
struct ifaddrs * if_addr_struct = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: use nullptr [modernize-use-nullptr]
struct ifaddrs * if_addr_struct = NULL; | |
struct ifaddrs * if_addr_struct = nullptr; |
clang-tidy review says "All clean, LGTM! 👍" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
clang-tidy review says "All clean, LGTM! 👍" |
clang-tidy review says "All clean, LGTM! 👍" |
1 similar comment
clang-tidy review says "All clean, LGTM! 👍" |
We're closing this PR because it hasn't been updated in a while. |
Proposed changes
Support network_interface in Apache Doris, the main changes are:
Issue Number: close #xxx
Problem summary
Describe your changes.
Checklist(Required)
Further comments
If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...