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 2022/10/14 06:53:38 UTC

[kylin] branch main updated: improve performance of getInstanceFromEnv

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

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


The following commit(s) were added to refs/heads/main by this push:
     new e603ecfd1f improve performance of getInstanceFromEnv
e603ecfd1f is described below

commit e603ecfd1f2535d3c3054958347423c39d4c0314
Author: zhaoliu4 <zh...@iflytek.com>
AuthorDate: Mon Oct 10 15:46:03 2022 +0800

    improve performance of getInstanceFromEnv
---
 .../java/org/apache/kylin/common/KylinConfig.java  | 54 +++++++++++-----------
 1 file changed, 28 insertions(+), 26 deletions(-)

diff --git a/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java b/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java
index de5c16bfee..cb23f3045e 100644
--- a/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java
+++ b/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java
@@ -65,7 +65,7 @@ public class KylinConfig extends KylinConfigBase {
     public static final String KYLIN_CONF = "KYLIN_CONF";
 
     // static cached instances
-    private static KylinConfig SYS_ENV_INSTANCE = null;
+    private static volatile KylinConfig SYS_ENV_INSTANCE = null;
 
     // static default Ordered Properties, only need load from classpath once
     private static OrderedProperties defaultOrderedProperties = new OrderedProperties();
@@ -134,38 +134,40 @@ public class KylinConfig extends KylinConfigBase {
     }
 
     public static KylinConfig getInstanceFromEnv(boolean allowConfigFileNoExist) {
-        synchronized (KylinConfig.class) {
-            KylinConfig config = THREAD_ENV_INSTANCE.get();
-            if (config != null) {
-                return config;
-            }
-
-            if (SYS_ENV_INSTANCE == null) {
-                try {
-                    //build default ordered properties will only be called once.
-                    //This logic no need called by CoProcessor due to it didn't call getInstanceFromEnv.
-                    buildDefaultOrderedProperties();
+        KylinConfig config = THREAD_ENV_INSTANCE.get();
+        if (config != null) {
+            return config;
+        }
 
-                    config = new KylinConfig();
+        if (SYS_ENV_INSTANCE == null) {
+            synchronized (KylinConfig.class) {
+                if (SYS_ENV_INSTANCE == null) {
                     try {
-                        config.reloadKylinConfig(buildSiteProperties());
-                    } catch (KylinConfigCannotInitException e) {
-                        logger.info("Kylin Config Can not Init Exception");
-                        if (!allowConfigFileNoExist) {
-                            throw e;
+                        //build default ordered properties will only be called once.
+                        //This logic no need called by CoProcessor due to it didn't call getInstanceFromEnv.
+                        buildDefaultOrderedProperties();
+
+                        config = new KylinConfig();
+                        try {
+                            config.reloadKylinConfig(buildSiteProperties());
+                        } catch (KylinConfigCannotInitException e) {
+                            logger.info("Kylin Config Can not Init Exception");
+                            if (!allowConfigFileNoExist) {
+                                throw e;
+                            }
                         }
-                    }
 
-                    VersionUtil.loadKylinVersion();
-                    logger.info("Initialized a new KylinConfig from getInstanceFromEnv : "
-                            + System.identityHashCode(config));
-                    SYS_ENV_INSTANCE = config;
-                } catch (IllegalArgumentException e) {
-                    throw new IllegalStateException("Failed to find KylinConfig ", e);
+                        VersionUtil.loadKylinVersion();
+                        logger.info("Initialized a new KylinConfig from getInstanceFromEnv : "
+                                + System.identityHashCode(config));
+                        SYS_ENV_INSTANCE = config;
+                    } catch (IllegalArgumentException e) {
+                        throw new IllegalStateException("Failed to find KylinConfig ", e);
+                    }
                 }
             }
-            return SYS_ENV_INSTANCE;
         }
+        return SYS_ENV_INSTANCE;
     }
 
     public static KylinConfig getInstanceFromEnv() {