You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2017/05/19 23:58:12 UTC
[34/50] [abbrv] kylin git commit:
KYLIN-2557-The-kylin-will-start-failed
KYLIN-2557-The-kylin-will-start-failed
Signed-off-by: Yang Li <li...@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/KYLIN-2624
Commit: e6a8a00b89dbdf922405f8586b43d1c9b99cff90
Parents: c8524ef
Author: 10069681 <pe...@zte.com.cn>
Authored: Tue May 9 10:47:50 2017 +0800
Committer: Yang Li <li...@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