You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by xx...@apache.org on 2023/02/27 08:00:57 UTC

[kylin] 17/34: KYLIN-5451 Avoid multiple local ip acquisitions

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

xxyu pushed a commit to branch kylin5
in repository https://gitbox.apache.org/repos/asf/kylin.git

commit b0c258904464eff63deea05c738a655a657f8ed6
Author: Yaguang Jia <ji...@foxmail.com>
AuthorDate: Thu Dec 29 14:32:07 2022 +0800

    KYLIN-5451 Avoid multiple local ip acquisitions
    
    * KYLIN-5451 Avoid multiple local ip acquisitions
---
 .../org/apache/kylin/common/util/AddressUtil.java    | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/core-common/src/main/java/org/apache/kylin/common/util/AddressUtil.java b/src/core-common/src/main/java/org/apache/kylin/common/util/AddressUtil.java
index 9f2c5a044d..71cd033143 100644
--- a/src/core-common/src/main/java/org/apache/kylin/common/util/AddressUtil.java
+++ b/src/core-common/src/main/java/org/apache/kylin/common/util/AddressUtil.java
@@ -32,11 +32,11 @@ import lombok.extern.slf4j.Slf4j;
 @Slf4j
 public class AddressUtil {
 
+    public static String MAINTAIN_MODE_MOCK_PORT = "0000";
+    private static String localIpAddressCache;
     @Setter
     private static HostInfoFetcher hostInfoFetcher = new DefaultHostInfoFetcher();
 
-    public static String MAINTAIN_MODE_MOCK_PORT = "0000";
-
     public static String getLocalInstance() {
         String serverIp = getLocalHostExactAddress();
         return serverIp + ":" + KylinConfig.getInstanceFromEnv().getServerPort();
@@ -79,13 +79,17 @@ public class AddressUtil {
     }
 
     public static String getLocalHostExactAddress() {
-        val localIpAddress = KylinConfig.getInstanceFromEnv().getServerIpAddress();
-        if (StringUtils.isNotBlank(localIpAddress)) {
-            return localIpAddress;
-        }
-        try (InetUtils inetUtils = new InetUtils(new InetUtilsProperties())) {
-            return inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
+        if (StringUtils.isEmpty(localIpAddressCache)) {
+            val localIpAddress = KylinConfig.getInstanceFromEnv().getServerIpAddress();
+            if (StringUtils.isNotBlank(localIpAddress)) {
+                localIpAddressCache = localIpAddress;
+            } else {
+                try (InetUtils inetUtils = new InetUtils(new InetUtilsProperties())) {
+                    localIpAddressCache = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
+                }
+            }
         }
+        return localIpAddressCache;
     }
 
     public static boolean isSameHost(String driverHost) {