kylin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From qhz...@apache.org
Subject [2/2] incubator-kylin git commit: KYLIN-992
Date Fri, 04 Sep 2015 14:05:08 GMT
KYLIN-992


Project: http://git-wip-us.apache.org/repos/asf/incubator-kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kylin/commit/b5c9722b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kylin/tree/b5c9722b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kylin/diff/b5c9722b

Branch: refs/heads/0.8
Commit: b5c9722bb5cc5f2c2a66eac3080fcfb3691103a4
Parents: eb0652a
Author: qianhao.zhou <qianzhou@ebay.com>
Authored: Wed Sep 2 17:19:24 2015 +0800
Committer: qianhao.zhou <qianzhou@ebay.com>
Committed: Fri Sep 4 22:04:36 2015 +0800

----------------------------------------------------------------------
 .../kylin/common/persistence/ResourceStore.java | 50 ++++++++++----------
 1 file changed, 25 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/b5c9722b/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceStore.java
----------------------------------------------------------------------
diff --git a/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceStore.java
b/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceStore.java
index ba61c37..b6ba550 100644
--- a/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceStore.java
+++ b/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceStore.java
@@ -72,35 +72,35 @@ abstract public class ResourceStore {
         }
         return knownImpl;
     }
-
-    public static ResourceStore getStore(KylinConfig kylinConfig) {
-        ResourceStore r = CACHE.get(kylinConfig);
+    
+    private static ResourceStore createResourceStore(KylinConfig kylinConfig) {
         List<Throwable> es = new ArrayList<Throwable>();
-        if (r == null) {
-            logger.info("Using metadata url " + kylinConfig.getMetadataUrl() + " for resource
store");
-            for (Class<? extends ResourceStore> cls : getKnownImpl()) {
-                try {
-                    r = cls.getConstructor(KylinConfig.class).newInstance(kylinConfig);
-                } catch (Exception e) {
-                    es.add(e);
-                } catch (NoClassDefFoundError er) {
-                    // may throw NoClassDefFoundError
-                    es.add(er);
-                }
-                if (r != null) {
-                    break;
-                }
-            }
-            if (r == null) {
-                for (Throwable exceptionOrError : es) {
-                    logger.error("Create new store instance failed ", exceptionOrError);
-                }
-                throw new IllegalArgumentException("Failed to find metadata store by url:
" + kylinConfig.getMetadataUrl());
+        logger.info("Using metadata url " + kylinConfig.getMetadataUrl() + " for resource
store");
+        for (Class<? extends ResourceStore> cls : getKnownImpl()) {
+            try {
+                return cls.getConstructor(KylinConfig.class).newInstance(kylinConfig);
+            } catch (Throwable e) {
+                es.add(e);
             }
+        }
+        for (Throwable exceptionOrError : es) {
+            logger.error("Create new store instance failed ", exceptionOrError);
+        }
+        throw new IllegalArgumentException("Failed to find metadata store by url: " + kylinConfig.getMetadataUrl());
+    }
 
-            CACHE.put(kylinConfig, r);
+    public static ResourceStore getStore(KylinConfig kylinConfig) {
+        if (CACHE.containsKey(kylinConfig)) {
+            return CACHE.get(kylinConfig);
+        }
+        synchronized (ResourceStore.class) {
+            if (CACHE.containsKey(kylinConfig)) {
+                return CACHE.get(kylinConfig);
+            } else {
+                CACHE.putIfAbsent(kylinConfig, createResourceStore(kylinConfig));
+            }
         }
-        return r;
+        return CACHE.get(kylinConfig);
     }
 
     // ============================================================================


Mime
View raw message