kylin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From liy...@apache.org
Subject [1/2] kylin git commit: KYLIN-2557-The-kylin-will-start-failed
Date Sun, 14 May 2017 12:14:55 GMT
Repository: kylin
Updated Branches:
  refs/heads/master c8524efe7 -> 1c80c29b2


KYLIN-2557-The-kylin-will-start-failed

Signed-off-by: Yang Li <liyang@apache.org>


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

Branch: refs/heads/master
Commit: e6a8a00b89dbdf922405f8586b43d1c9b99cff90
Parents: c8524ef
Author: 10069681 <peng.jianhua@zte.com.cn>
Authored: Tue May 9 10:47:50 2017 +0800
Committer: Yang Li <liyang@apache.org>
Committed: Sun May 14 19:45:48 2017 +0800

----------------------------------------------------------------------
 .../kylin/storage/hbase/HBaseConnection.java    | 21 +++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/e6a8a00b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/HBaseConnection.java
----------------------------------------------------------------------
diff --git a/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/HBaseConnection.java
b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/HBaseConnection.java
index f0b9428..ef82641 100644
--- a/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/HBaseConnection.java
+++ b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/HBaseConnection.java
@@ -33,6 +33,7 @@ import org.apache.hadoop.hbase.client.ConnectionFactory;
 import org.apache.hadoop.hbase.util.Threads;
 import org.apache.hadoop.hdfs.DFSConfigKeys;
 import org.apache.kylin.common.KylinConfig;
+import org.apache.kylin.common.lock.DistributedLock;
 import org.apache.kylin.common.persistence.StorageException;
 import org.apache.kylin.common.util.HadoopUtil;
 import org.slf4j.Logger;
@@ -66,6 +67,8 @@ public class HBaseConnection {
 
     private static ExecutorService coprocessorPool = null;
 
+    private static DistributedLock lock = null;
+
     static {
         Runtime.getRuntime().addShutdownHook(new Thread() {
             @Override
@@ -267,6 +270,7 @@ public class HBaseConnection {
     public static void createHTableIfNeeded(Connection conn, String table, String... families)
throws IOException {
         Admin hbase = conn.getAdmin();
         TableName tableName = TableName.valueOf(table);
+        boolean hasLock = false;
         try {
             if (tableExists(conn, table)) {
                 logger.debug("HTable '" + table + "' already exists");
@@ -290,6 +294,14 @@ public class HBaseConnection {
                 return;
             }
 
+            lock = KylinConfig.getInstanceFromEnv().getDistributedLockFactory().lockForCurrentProcess();
+            hasLock = lock.lock(getLockPath(table), Long.MAX_VALUE);
+
+            if (tableExists(conn, table)) {
+                logger.debug("HTable '" + table + "' already exists");
+                return;
+            }
+
             logger.debug("Creating HTable '" + table + "'");
 
             HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(table));
@@ -307,6 +319,9 @@ public class HBaseConnection {
             logger.debug("HTable '" + table + "' created");
         } finally {
             hbase.close();
+            if (hasLock && lock != null) {
+                lock.unlock(getLockPath(table));
+            }
         }
     }
 
@@ -350,4 +365,8 @@ public class HBaseConnection {
         }
     }
 
-}
+    private static String getLockPath(String pathName) {
+        return "/create_htable/" + pathName + "/lock";
+    }
+
+}
\ No newline at end of file


Mime
View raw message