This is an automated email from the ASF dual-hosted git repository.

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 66e1a16816ee191a7e3568cb5bfe7a0294eb2b06
Author: zhangdong <493738...@qq.com>
AuthorDate: Sat Sep 2 21:24:11 2023 +0800

    [Enhance](ip)optimize priority_ network matching logic (#23784)
    
    If the user has configured the wrong priority_network, direct startup 
failure to avoid users mistakenly assuming that the configuration is correct
    If the user has not configured p_ n. Select only the last IP from the IPv4 
list, rather than selecting from all IPs, to avoid users' servers not 
supporting IPv4
---
 .../org/apache/doris/service/FrontendOptions.java  | 47 +++++++++++++---------
 1 file changed, 28 insertions(+), 19 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendOptions.java 
b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendOptions.java
index bad90822f6..f94e090709 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendOptions.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendOptions.java
@@ -27,6 +27,7 @@ import com.google.common.net.InetAddresses;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
+import java.net.Inet4Address;
 import java.net.Inet6Address;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
@@ -57,35 +58,43 @@ public class FrontendOptions {
         }
     }
 
-
+    // 1. If priority_networks is configured . Obtain the IP that complies 
with the rules,
+    // and stop the process if it is not obtained
+    // 2. If the priority_networks is not configured, priority should be given 
to obtaining non loopback IPv4 addresses.
+    // If not, use loopback
     static void initAddrUseIp(List<InetAddress> hosts) {
         useFqdn = false;
         analyzePriorityCidrs();
-        // if not set frontend_address, get a non-loopback ip
-        InetAddress loopBack = null;
         boolean hasMatchedIp = false;
-        for (InetAddress addr : hosts) {
-            LOG.debug("check ip address: {}", addr);
-            if (addr.isLoopbackAddress()) {
-                loopBack = addr;
-            } else if (!priorityCidrs.isEmpty()) {
+        if (!priorityCidrs.isEmpty()) {
+            for (InetAddress addr : hosts) {
+                LOG.debug("check ip address: {}", addr);
                 if (isInPriorNetwork(addr.getHostAddress())) {
                     localAddr = addr;
                     hasMatchedIp = true;
                     break;
                 }
-            } else {
-                localAddr = addr;
-                break;
             }
-        }
-        //if all ips not match the priority_networks then print the warning log
-        if (!priorityCidrs.isEmpty() && !hasMatchedIp) {
-            LOG.warn("ip address range configured for priority_networks does 
not include the current IP address");
-        }
-        // nothing found, use loopback addr
-        if (localAddr == null) {
-            localAddr = loopBack;
+            //if all ips not match the priority_networks then print the err 
log and exit
+            if (!hasMatchedIp) {
+                LOG.error("ip address range configured for priority_networks 
does not include the current IP address");
+                System.exit(-1);
+            }
+        } else {
+            // if not set frontend_address, get a non-loopback ip
+            InetAddress loopBack = null;
+            for (InetAddress addr : hosts) {
+                if (addr.isLoopbackAddress()) {
+                    loopBack = addr;
+                } else if (addr instanceof Inet4Address) {
+                    localAddr = addr;
+                    break;
+                }
+            }
+            // nothing found, use loopback addr
+            if (localAddr == null) {
+                localAddr = loopBack;
+            }
         }
         LOG.info("local address: {}.", localAddr);
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to