LENS-796 : Slow response times for /metastore/nativetables API
Project: http://git-wip-us.apache.org/repos/asf/lens/repo Commit: http://git-wip-us.apache.org/repos/asf/lens/commit/5c9bae09 Tree: http://git-wip-us.apache.org/repos/asf/lens/tree/5c9bae09 Diff: http://git-wip-us.apache.org/repos/asf/lens/diff/5c9bae09 Branch: refs/heads/current-release-line Commit: 5c9bae096351960f4790e11f76a5d7665d8e8d3d Parents: aeaae68 Author: Deepak Barr <[email protected]> Authored: Tue Oct 6 12:52:29 2015 +0530 Committer: Rajat Khandelwal <[email protected]> Committed: Tue Oct 6 12:52:29 2015 +0530 ---------------------------------------------------------------------- .../metastore/CubeMetastoreServiceImpl.java | 60 ++++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lens/blob/5c9bae09/lens-server/src/main/java/org/apache/lens/server/metastore/CubeMetastoreServiceImpl.java ---------------------------------------------------------------------- diff --git a/lens-server/src/main/java/org/apache/lens/server/metastore/CubeMetastoreServiceImpl.java b/lens-server/src/main/java/org/apache/lens/server/metastore/CubeMetastoreServiceImpl.java index 37cebfe..4c8b525 100644 --- a/lens-server/src/main/java/org/apache/lens/server/metastore/CubeMetastoreServiceImpl.java +++ b/lens-server/src/main/java/org/apache/lens/server/metastore/CubeMetastoreServiceImpl.java @@ -38,14 +38,13 @@ import org.apache.lens.server.api.metastore.CubeMetastoreService; import org.apache.lens.server.session.LensSessionImpl; import org.apache.commons.lang.StringUtils; +import org.apache.hadoop.hive.metastore.IMetaStoreClient; import org.apache.hadoop.hive.metastore.api.*; import org.apache.hadoop.hive.ql.metadata.*; import org.apache.hadoop.hive.ql.metadata.Partition; import org.apache.hadoop.hive.ql.metadata.Table; import org.apache.hadoop.hive.ql.parse.ParseException; import org.apache.hive.service.cli.CLIService; -import org.apache.hive.service.cli.HiveSQLException; -import org.apache.thrift.TException; import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; @@ -1198,28 +1197,37 @@ public class CubeMetastoreServiceImpl extends BaseLensService implements CubeMet } } - private List<String> getTablesFromDB(LensSessionHandle sessionid, - String dbName, boolean prependDbName) - throws MetaException, UnknownDBException, HiveSQLException, TException, LensException { - List<String> tables = getSession(sessionid).getMetaStoreClient().getAllTables( - dbName); - List<String> result = new ArrayList<String>(); - if (tables != null && !tables.isEmpty()) { - Iterator<String> it = tables.iterator(); - while (it.hasNext()) { - String tblName = it.next(); - org.apache.hadoop.hive.metastore.api.Table tbl = - getSession(sessionid).getMetaStoreClient().getTable(dbName, tblName); - if (tbl.getParameters().get(MetastoreConstants.TABLE_TYPE_KEY) == null) { - if (prependDbName) { - result.add(dbName + "." + tblName); - } else { - result.add(tblName); + private List<String> getNativeTablesFromDB(LensSessionHandle sessionid, String dbName, boolean prependDbName) + throws LensException { + IMetaStoreClient msc = null; + try { + msc = getSession(sessionid).getMetaStoreClient(); + List<String> tables = msc.getAllTables( + dbName); + List<String> result = new ArrayList<String>(); + if (tables != null && !tables.isEmpty()) { + List<org.apache.hadoop.hive.metastore.api.Table> tblObjects = + msc.getTableObjectsByName(dbName, tables); + Iterator<org.apache.hadoop.hive.metastore.api.Table> it = tblObjects.iterator(); + while (it.hasNext()) { + org.apache.hadoop.hive.metastore.api.Table tbl = it.next(); + if (tbl.getParameters().get(MetastoreConstants.TABLE_TYPE_KEY) == null) { + if (prependDbName) { + result.add(dbName + "." + tbl.getTableName()); + } else { + result.add(tbl.getTableName()); + } } } } + return result; + } catch (Exception e) { + throw new LensException("Error getting native tables from DB", e); + } finally { + if (null != msc) { + msc.close(); + } } - return result; } @Override @@ -1240,24 +1248,16 @@ public class CubeMetastoreServiceImpl extends BaseLensService implements CubeMet } List<String> tables; if (!StringUtils.isBlank(dbName)) { - tables = getTablesFromDB(sessionid, dbName, false); + tables = getNativeTablesFromDB(sessionid, dbName, false); } else { log.info("Getting tables from all dbs"); List<String> alldbs = getAllDatabases(sessionid); tables = new ArrayList<String>(); for (String db : alldbs) { - tables.addAll(getTablesFromDB(sessionid, db, true)); + tables.addAll(getNativeTablesFromDB(sessionid, db, true)); } } return tables; - } catch (HiveSQLException e) { - throw new LensException(e); - } catch (MetaException e) { - throw new LensException(e); - } catch (UnknownDBException e) { - throw new NotFoundException("Database " + dbName + " does not exist"); - } catch (TException e) { - throw new LensException(e); } catch (HiveException e) { throw new LensException(e); } finally {
