You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by da...@apache.org on 2019/05/05 16:57:36 UTC
[hive] branch master updated: HIVE-20615: CachedStore: Background
refresh thread bug fixes (Vaibhav Gumashta, reviewed by Daniel Dai)
This is an automated email from the ASF dual-hosted git repository.
daijy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push:
new aebfaad HIVE-20615: CachedStore: Background refresh thread bug fixes (Vaibhav Gumashta, reviewed by Daniel Dai)
aebfaad is described below
commit aebfaad137226a69a7424c9d377625963e7e4fdd
Author: Daniel Dai <da...@gmail.com>
AuthorDate: Sun May 5 09:56:30 2019 -0700
HIVE-20615: CachedStore: Background refresh thread bug fixes (Vaibhav Gumashta, reviewed by Daniel Dai)
---
.../hadoop/hive/metastore/cache/CacheUtils.java | 4 ++
.../hadoop/hive/metastore/cache/CachedStore.java | 7 +++-
.../hadoop/hive/metastore/cache/SharedCache.java | 45 +++++++++++++++-------
3 files changed, 41 insertions(+), 15 deletions(-)
diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/CacheUtils.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/CacheUtils.java
index 944c813..d50fa13 100644
--- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/CacheUtils.java
+++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/CacheUtils.java
@@ -40,6 +40,10 @@ public class CacheUtils {
return buildKey(catName.toLowerCase(), dbName.toLowerCase());
}
+ public static String buildDbKeyWithDelimiterSuffix(String catName, String dbName) {
+ return buildKey(catName.toLowerCase(), dbName.toLowerCase()) + delimit;
+ }
+
/**
* Builds a key for the partition cache which is concatenation of partition values, each value
* separated by a delimiter
diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/CachedStore.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/CachedStore.java
index 2d738f6..1fac51e 100644
--- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/CachedStore.java
+++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/CachedStore.java
@@ -490,7 +490,7 @@ public class CachedStore implements RawStore, Configurable {
List<ColumnStatistics> partitionColStats = null;
AggrStats aggrStatsAllPartitions = null;
AggrStats aggrStatsAllButDefaultPartition = null;
- if (table.isSetPartitionKeys()) {
+ if (!table.getPartitionKeys().isEmpty()) {
Deadline.startTimer("getPartitions");
partitions = rawStore.getPartitions(catName, dbName, tblName, Integer.MAX_VALUE);
Deadline.stopTimer();
@@ -561,6 +561,7 @@ public class CachedStore implements RawStore, Configurable {
LOG.debug("Processed database: {}. Cached {} / {} databases so far.", dbName,
++numberOfDatabasesCachedSoFar, databases.size());
}
+ sharedCache.clearDirtyFlags();
completePrewarm(startTime);
}
}
@@ -724,6 +725,7 @@ public class CachedStore implements RawStore, Configurable {
} else {
try {
triggerPreWarm(rawStore);
+ shouldRunPrewarm = false;
} catch (Exception e) {
LOG.error("Prewarm failure", e);
return;
@@ -815,7 +817,6 @@ public class CachedStore implements RawStore, Configurable {
if (table != null && !table.isSetPartitionKeys()) {
List<String> colNames = MetaStoreUtils.getColumnNamesForTable(table);
Deadline.startTimer("getTableColumnStatistics");
-
ColumnStatistics tableColStats =
rawStore.getTableColumnStatistics(catName, dbName, tblName, colNames);
Deadline.stopTimer();
@@ -865,7 +866,9 @@ public class CachedStore implements RawStore, Configurable {
rawStore.getPartitionColumnStatistics(catName, dbName, tblName, partNames, colNames);
Deadline.stopTimer();
sharedCache.refreshPartitionColStatsInCache(catName, dbName, tblName, partitionColStats);
+ Deadline.startTimer("getPartitionsByNames");
List<Partition> parts = rawStore.getPartitionsByNames(catName, dbName, tblName, partNames);
+ Deadline.stopTimer();
// Also save partitions for consistency as they have the stats state.
for (Partition part : parts) {
sharedCache.alterPartitionInCache(catName, dbName, tblName, part.getValues(), part);
diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/SharedCache.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/SharedCache.java
index 1c23022..a0636b6 100644
--- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/SharedCache.java
+++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/SharedCache.java
@@ -1200,7 +1200,7 @@ public class SharedCache {
LOG.debug("Current cache size: {} bytes", currentCacheSizeInBytes);
}
if (!table.isSetPartitionKeys() && (tableColStats != null)) {
- if (!tblWrapper.updateTableColStats(tableColStats.getStatsObj())) {
+ if (table.getPartitionKeys().isEmpty() && (tableColStats != null)) {
return false;
}
} else {
@@ -1227,6 +1227,10 @@ public class SharedCache {
tblWrapper.cacheAggrPartitionColStats(aggrStatsAllPartitions,
aggrStatsAllButDefaultPartition);
}
+ tblWrapper.isPartitionCacheDirty.set(false);
+ tblWrapper.isTableColStatsCacheDirty.set(false);
+ tblWrapper.isPartitionColStatsCacheDirty.set(false);
+ tblWrapper.isAggrPartitionColStatsCacheDirty.set(false);
try {
cacheLock.writeLock().lock();
// 2. Skip overwriting exisiting table object
@@ -1317,11 +1321,13 @@ public class SharedCache {
//in case of retry, ignore second try.
return;
}
- byte[] sdHash = tblWrapper.getSdHash();
- if (sdHash != null) {
- decrSd(sdHash);
+ if (tblWrapper != null) {
+ byte[] sdHash = tblWrapper.getSdHash();
+ if (sdHash != null) {
+ decrSd(sdHash);
+ }
+ isTableCacheDirty.set(true);
}
- isTableCacheDirty.set(true);
} finally {
cacheLock.writeLock().unlock();
}
@@ -1438,27 +1444,34 @@ public class SharedCache {
public void refreshTablesInCache(String catName, String dbName, List<Table> tables) {
try {
- cacheLock.writeLock().lock();
if (isTableCacheDirty.compareAndSet(true, false)) {
LOG.debug("Skipping table cache update; the table list we have is dirty.");
return;
}
- Map<String, TableWrapper> newTableCache = new HashMap<>();
+ Map<String, TableWrapper> newCacheForDB = new TreeMap<>();
for (Table tbl : tables) {
String tblName = StringUtils.normalizeIdentifier(tbl.getTableName());
- TableWrapper tblWrapper =
- tableCache.get(CacheUtils.buildTableKey(catName, dbName, tblName));
+ TableWrapper tblWrapper = tableCache.get(CacheUtils.buildTableKey(catName, dbName, tblName));
if (tblWrapper != null) {
tblWrapper.updateTableObj(tbl, this);
} else {
tblWrapper = createTableWrapper(catName, dbName, tblName, tbl);
}
- newTableCache.put(CacheUtils.buildTableKey(catName, dbName, tblName), tblWrapper);
+ newCacheForDB.put(CacheUtils.buildTableKey(catName, dbName, tblName), tblWrapper);
}
- tableCache.clear();
- tableCache = newTableCache;
+ cacheLock.writeLock().lock();
+ Iterator<Entry<String, TableWrapper>> entryIterator = tableCache.entrySet().iterator();
+ while (entryIterator.hasNext()) {
+ String key = entryIterator.next().getKey();
+ if (key.startsWith(CacheUtils.buildDbKeyWithDelimiterSuffix(catName, dbName))) {
+ entryIterator.remove();
+ }
+ }
+ tableCache.putAll(newCacheForDB);
} finally {
- cacheLock.writeLock().unlock();
+ if (cacheLock.writeLock().isHeldByCurrentThread()) {
+ cacheLock.writeLock().unlock();
+ }
}
}
@@ -1904,6 +1917,12 @@ public class SharedCache {
isCatalogCacheDirty.set(false);
}
+ void clearDirtyFlags() {
+ isCatalogCacheDirty.set(false);
+ isDatabaseCacheDirty.set(false);
+ isTableCacheDirty.set(false);
+ }
+
public long getUpdateCount() {
return cacheUpdateCount.get();
}