From 81cd987027d7fcda1de7130c18452d1676a081f9 Mon Sep 17 00:00:00 2001 From: gavin Date: Fri, 24 Oct 2014 05:24:18 +0900 Subject: [PATCH] edit hiveserver2 session's metastore client to use ThreadLocal client --- .../hive/service/cli/session/HiveSessionImpl.java | 25 ++++++------------- 1 files changed, 8 insertions(+), 17 deletions(-) diff --git a/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java b/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java index fa28a6b..cabf32a 100644 --- a/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java +++ b/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java @@ -35,12 +35,13 @@ import org.apache.hadoop.hive.common.cli.IHiveFileProcessor; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.conf.HiveConf.ConfVars; -import org.apache.hadoop.hive.metastore.HiveMetaStoreClient; import org.apache.hadoop.hive.metastore.IMetaStoreClient; import org.apache.hadoop.hive.metastore.api.MetaException; import org.apache.hadoop.hive.ql.exec.FetchFormatter; import org.apache.hadoop.hive.ql.exec.ListSinkOperator; import org.apache.hadoop.hive.ql.history.HiveHistory; +import org.apache.hadoop.hive.ql.metadata.Hive; +import org.apache.hadoop.hive.ql.metadata.HiveException; import org.apache.hadoop.hive.ql.processors.SetProcessor; import org.apache.hadoop.hive.ql.session.SessionState; import org.apache.hadoop.hive.shims.ShimLoader; @@ -81,7 +82,6 @@ private SessionManager sessionManager; private OperationManager operationManager; - private IMetaStoreClient metastoreClient = null; private final Set opHandleSet = new HashSet(); private boolean isOperationLogEnabled; private File sessionLogDir; @@ -327,14 +327,13 @@ public HiveConf getHiveConf() { @Override public IMetaStoreClient getMetaStoreClient() throws HiveSQLException { - if (metastoreClient == null) { - try { - metastoreClient = new HiveMetaStoreClient(getHiveConf()); - } catch (MetaException e) { - throw new HiveSQLException(e); - } + try { + return Hive.get(getHiveConf()).getMSC(); + } catch (HiveException e) { + throw new HiveSQLException("Failed to get metastore connection", e); + } catch (MetaException e) { + throw new HiveSQLException("Failed to get metastore connection", e); } - return metastoreClient; } @Override @@ -550,14 +549,6 @@ public OperationHandle getFunctions(String catalogName, String schemaName, Strin public void close() throws HiveSQLException { try { acquire(true); - /** - * For metadata operations like getTables(), getColumns() etc, - * the session allocates a private metastore handler which should be - * closed at the end of the session - */ - if (metastoreClient != null) { - metastoreClient.close(); - } // Iterate through the opHandles and close their operations for (OperationHandle opHandle : opHandleSet) { operationManager.closeOperation(opHandle); -- 1.7.1