diff --git a/service/src/java/org/apache/hive/service/server/ThreadWithGarbageCleanup.java b/service/src/java/org/apache/hive/service/server/ThreadWithGarbageCleanup.java index 1ec8097..a8ed93e 100644 --- a/service/src/java/org/apache/hive/service/server/ThreadWithGarbageCleanup.java +++ b/service/src/java/org/apache/hive/service/server/ThreadWithGarbageCleanup.java @@ -68,7 +68,11 @@ private void cleanRawStore() { public void cacheThreadLocalRawStore() { Long threadId = this.getId(); RawStore threadLocalRawStore = HiveMetaStore.HMSHandler.getRawStore(); - if (threadLocalRawStore != null && !threadRawStoreMap.containsKey(threadId)) { + if (threadLocalRawStore == null) { + LOG.debug("Thread Local RawStore is null, for the thread: " + + this.getName() + " and so removing entry from threadRawStoreMap."); + threadRawStoreMap.remove(threadId); + } else { LOG.debug("Adding RawStore: " + threadLocalRawStore + ", for the thread: " + this.getName() + " to threadRawStoreMap for future cleanup."); threadRawStoreMap.put(threadId, threadLocalRawStore); diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index 2ccaaa4..55f43b0 100644 --- a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -695,9 +695,15 @@ public static RawStore getMSForConf(Configuration conf) throws MetaException { RawStore ms = threadLocalMS.get(); if (ms == null) { ms = newRawStoreForConf(conf); - ms.verifySchema(); + try { + ms.verifySchema(); + } catch (MetaException e) { + ms.shutdown(); + throw e; + } threadLocalMS.set(ms); ms = threadLocalMS.get(); + LOG.info("Created RawStore: " + ms + " from thread id: " + Thread.currentThread().getId()); } return ms; } diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java index b8eb173..8f8f592 100644 --- a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java +++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java @@ -419,6 +419,7 @@ private void initialize(Properties dsProps) { initializeHelper(dsProps); return; // If we reach here, we succeed. } catch (Exception e){ + shutdown(); numTries--; boolean retriable = isRetriableException(e); if ((numTries > 0) && retriable){ @@ -480,6 +481,8 @@ private void initializeHelper(Properties dsProps) { LOG.info("ObjectStore, initialize called"); prop = dsProps; pm = getPersistenceManager(); + LOG.info("RawStore: {}, with PersistenceManager: {}" + + " created in the thread with id: {}", this, pm, Thread.currentThread().getId()); try { String productName = MetaStoreDirectSql.getProductName(pm); sqlGenerator = new SQLGenerator(DatabaseProduct.determineDatabaseProduct(productName), conf); @@ -497,8 +500,6 @@ private void initializeHelper(Properties dsProps) { directSql = new MetaStoreDirectSql(pm, conf, schema); } } - LOG.debug("RawStore: {}, with PersistenceManager: {}" + - " created in the thread with id: {}", this, pm, Thread.currentThread().getId()); } private DatabaseProduct determineDatabaseProduct() { @@ -694,7 +695,7 @@ public PersistenceManager getPersistenceManager() { @Override public void shutdown() { - LOG.debug("RawStore: {}, with PersistenceManager: {} will be shutdown", this, pm); + LOG.info("RawStore: {}, with PersistenceManager: {} will be shutdown", this, pm); if (pm != null) { pm.close(); pm = null;