adesh-rao commented on a change in pull request #1109: URL: https://github.com/apache/hive/pull/1109#discussion_r449401898
########## File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/SharedCache.java ########## @@ -1870,6 +2228,122 @@ public void removePartitionsFromCache(String catName, String dbName, String tblN return parts; } + public List<SQLPrimaryKey> listCachedPrimaryKeys(String catName, String dbName, String tblName) { + List<SQLPrimaryKey> keys = new ArrayList<>(); + try { + cacheLock.readLock().lock(); + TableWrapper tblWrapper = tableCache.getIfPresent(CacheUtils.buildTableKey(catName, dbName, tblName)); + if (tblWrapper != null) { + keys = tblWrapper.getPrimaryKeys(); + } + } finally { + cacheLock.readLock().unlock(); + } + return keys; + } + + public List<SQLForeignKey> listCachedForeignKeys(String catName, String foreignDbName, String foreignTblName, + String parentDbName, String parentTblName) { + List<SQLForeignKey> keys = new ArrayList<>(); + try { + cacheLock.readLock().lock(); + TableWrapper tblWrapper = tableCache.getIfPresent(CacheUtils.buildTableKey(catName, foreignDbName, foreignTblName)); + if (tblWrapper != null) { + keys = tblWrapper.getForeignKeys(); + } + } finally { + cacheLock.readLock().unlock(); + } + + // filter out required foreign keys based on parent db/tbl name + if (!StringUtils.isEmpty(parentTblName) && !StringUtils.isEmpty(parentDbName)) { Review comment: Even if tblWrapper is null, keys will be empty list and hence an empty list will be returned. So this should be fine, right? In case we move it to above if block, and assuming the list is not-empty, we will keep the read lock on for a longer duration (though only in milliseconds or even less), that's why I added it below. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org