From 48721885343ff8707fb9cebe31f69dabff848a6b Mon Sep 17 00:00:00 2001 From: gavin Date: Wed, 15 Oct 2014 14:53:40 +0900 Subject: [PATCH] edit hiveserver2 session's metastore client to use ThreadLocal client --- .../hive/service/cli/session/HiveSessionImpl.java | 21 ++++++++----------- 1 files changed, 9 insertions(+), 12 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 a9d5902..9bead1f 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 @@ -28,12 +28,13 @@ import org.apache.commons.logging.LogFactory; 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.session.SessionState; import org.apache.hive.common.util.HiveVersionInfo; import org.apache.hive.service.auth.HiveAuthFactory; @@ -77,7 +78,6 @@ private SessionManager sessionManager; private OperationManager operationManager; - private IMetaStoreClient metastoreClient = null; private final Set opHandleSet = new HashSet(); public HiveSessionImpl(TProtocolVersion protocol, String username, String password, @@ -169,14 +169,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 @@ -397,9 +396,7 @@ public void close() throws HiveSQLException { * the session allocates a private metastore handler which should be * closed at the end of the session */ - if (metastoreClient != null) { - metastoreClient.close(); - } + Hive.closeCurrent(); // Iterate through the opHandles and close their operations for (OperationHandle opHandle : opHandleSet) { operationManager.closeOperation(opHandle); -- 1.7.1