Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,8 @@ public Map<String, PartitionItem> getNameToPartitionItems() {
if (CollectionUtils.isEmpty(this.getPartitionColumns())) {
return Collections.emptyMap();
}
HiveMetaStoreCache cache = Env.getCurrentEnv().getExtMetaCacheMgr()
.getMetaStoreCache((HMSExternalCatalog) this.getCatalog());
List<Type> partitionColumnTypes = this.getPartitionColumnTypes(MvccUtil.getSnapshotFromContext(this));
HiveMetaStoreCache.HivePartitionValues hivePartitionValues = cache.getPartitionValues(
this, partitionColumnTypes);
HiveMetaStoreCache.HivePartitionValues hivePartitionValues = getHivePartitionValues(
MvccUtil.getSnapshotFromContext(this));
Map<Long, PartitionItem> idToPartitionItem = hivePartitionValues.getIdToPartitionItem();
// transfer id to name
BiMap<Long, String> idToName = hivePartitionValues.getPartitionNameToIdMap().inverse();
Expand Down Expand Up @@ -983,10 +980,10 @@ public MTMVSnapshotIf getTableSnapshot(Optional<MvccSnapshot> snapshot) throws A

@Override
public long getNewestUpdateVersionOrTime() {
HiveMetaStoreCache.HivePartitionValues hivePartitionValues = getHivePartitionValues(
MvccUtil.getSnapshotFromContext(this));
HiveMetaStoreCache cache = Env.getCurrentEnv().getExtMetaCacheMgr()
.getMetaStoreCache((HMSExternalCatalog) getCatalog());
HiveMetaStoreCache.HivePartitionValues hivePartitionValues = cache.getPartitionValues(this,
getPartitionColumnTypes(MvccUtil.getSnapshotFromContext(this)));
List<HivePartition> partitionList = cache.getAllPartitionsWithCache(this,
Lists.newArrayList(hivePartitionValues.getPartitionValuesMap().values()));
if (CollectionUtils.isEmpty(partitionList)) {
Expand Down Expand Up @@ -1062,16 +1059,15 @@ private HiveMetaStoreCache.HivePartitionValues getAllPartitionValues() {
if (isView()) {
return null;
}
HiveMetaStoreCache cache = Env.getCurrentEnv().getExtMetaCacheMgr()
.getMetaStoreCache((HMSExternalCatalog) catalog);
List<Type> partitionColumnTypes = getPartitionColumnTypes(MvccUtil.getSnapshotFromContext(this));
Optional<MvccSnapshot> snapshot = MvccUtil.getSnapshotFromContext(this);
List<Type> partitionColumnTypes = getPartitionColumnTypes(snapshot);
HiveMetaStoreCache.HivePartitionValues partitionValues = null;
// Get table partitions from cache.
if (!partitionColumnTypes.isEmpty()) {
// It is ok to get partition values from cache,
// no need to worry that this call will invalid or refresh the cache.
// because it has enough space to keep partition info of all tables in cache.
partitionValues = cache.getPartitionValues(this, partitionColumnTypes);
partitionValues = getHivePartitionValues(snapshot);
if (partitionValues == null || partitionValues.getPartitionNameToIdMap() == null) {
LOG.warn("Partition values for hive table {} is null", name);
} else {
Expand Down Expand Up @@ -1192,4 +1188,25 @@ private Table loadHiveTable() {
HMSCachedClient client = ((HMSExternalCatalog) catalog).getClient();
return client.getTable(getRemoteDbName(), remoteName);
}

public HiveMetaStoreCache.HivePartitionValues getHivePartitionValues(Optional<MvccSnapshot> snapshot) {
HiveMetaStoreCache cache = Env.getCurrentEnv().getExtMetaCacheMgr()
.getMetaStoreCache((HMSExternalCatalog) this.getCatalog());
try {
List<Type> partitionColumnTypes = this.getPartitionColumnTypes(snapshot);
return cache.getPartitionValues(this, partitionColumnTypes);
} catch (Exception e) {
if (e.getMessage().contains(HiveMetaStoreCache.ERR_CACHE_INCONSISTENCY)) {
LOG.warn("Hive metastore cache inconsistency detected for table: {}.{}.{}. "
+ "Clearing cache and retrying to get partition values.",
this.getCatalog().getName(), this.getDbName(), this.getName(), e);
ExternalSchemaCache schemaCache = Env.getCurrentEnv().getExtMetaCacheMgr().getSchemaCache(catalog);
schemaCache.invalidateTableCache(this);
List<Type> partitionColumnTypes = this.getPartitionColumnTypes(snapshot);
return cache.getPartitionValues(this, partitionColumnTypes);
} else {
throw e;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ public Map<String, PartitionItem> getAndCopyPartitionItems(Optional<MvccSnapshot
@Override
public MTMVSnapshotIf getPartitionSnapshot(String partitionName, MTMVRefreshContext context,
Optional<MvccSnapshot> snapshot) throws AnalysisException {
HiveMetaStoreCache.HivePartitionValues hivePartitionValues = hmsTable.getHivePartitionValues(snapshot);
Long partitionId = getPartitionIdByNameOrAnalysisException(partitionName, hivePartitionValues);
HiveMetaStoreCache cache = Env.getCurrentEnv().getExtMetaCacheMgr()
.getMetaStoreCache((HMSExternalCatalog) hmsTable.getCatalog());
HiveMetaStoreCache.HivePartitionValues hivePartitionValues = cache.getPartitionValues(
hmsTable, hmsTable.getPartitionColumnTypes(snapshot));
Long partitionId = getPartitionIdByNameOrAnalysisException(partitionName, hivePartitionValues);
HivePartition hivePartition = getHivePartitionByIdOrAnalysisException(partitionId,
hivePartitionValues, cache);
return new MTMVTimestampSnapshot(hivePartition.getLastModifiedTime());
Expand All @@ -95,10 +94,9 @@ public MTMVSnapshotIf getTableSnapshot(Optional<MvccSnapshot> snapshot) throws A
HivePartition maxPartition = null;
long maxVersionTime = 0L;
long visibleVersionTime;
HiveMetaStoreCache.HivePartitionValues hivePartitionValues = hmsTable.getHivePartitionValues(snapshot);
HiveMetaStoreCache cache = Env.getCurrentEnv().getExtMetaCacheMgr()
.getMetaStoreCache((HMSExternalCatalog) hmsTable.getCatalog());
HiveMetaStoreCache.HivePartitionValues hivePartitionValues = cache.getPartitionValues(
hmsTable, hmsTable.getPartitionColumnTypes(snapshot));
List<HivePartition> partitionList = cache.getAllPartitionsWithCache(hmsTable,
Lists.newArrayList(hivePartitionValues.getPartitionValuesMap().values()));
if (CollectionUtils.isEmpty(partitionList)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
public class HiveMetaStoreCache {
private static final Logger LOG = LogManager.getLogger(HiveMetaStoreCache.class);
public static final String HIVE_DEFAULT_PARTITION = "__HIVE_DEFAULT_PARTITION__";
public static final String ERR_CACHE_INCONSISTENCY = "ERR_CACHE_INCONSISTENCY: ";

private final HMSExternalCatalog catalog;
private JobConf jobConf;
Expand Down Expand Up @@ -276,11 +277,12 @@ private HivePartitionValues loadPartitionValues(PartitionValueCacheKey key) {
partitionNameToIdMap, idToUniqueIdsMap, singleUidToColumnRangeMap, partitionValuesMap);
}

public ListPartitionItem toListPartitionItem(String partitionName, List<Type> types) {
private ListPartitionItem toListPartitionItem(String partitionName, List<Type> types) {
// Partition name will be in format: nation=cn/city=beijing
// parse it to get values "cn" and "beijing"
List<String> partitionValues = HiveUtil.toPartitionValues(partitionName);
Preconditions.checkState(partitionValues.size() == types.size(), partitionName + " vs. " + types);
Preconditions.checkState(partitionValues.size() == types.size(),
ERR_CACHE_INCONSISTENCY + partitionName + " vs. " + types);
List<PartitionValue> values = Lists.newArrayListWithExpectedSize(types.size());
for (String partitionValue : partitionValues) {
values.add(new PartitionValue(partitionValue, HIVE_DEFAULT_PARTITION.equals(partitionValue)));
Expand Down Expand Up @@ -433,6 +435,7 @@ public HivePartitionValues getPartitionValues(ExternalTable dorisTable, List<Typ
return getPartitionValues(key);
}

@VisibleForTesting
public HivePartitionValues getPartitionValues(PartitionValueCacheKey key) {
return partitionValuesCache.get(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1823,10 +1823,8 @@ private static List<TRow> partitionValuesMetadataResultForHmsTable(HMSExternalTa
"column " + colNames + " does not match partition columns of table " + tbl.getName());
}

HiveMetaStoreCache cache = Env.getCurrentEnv().getExtMetaCacheMgr()
.getMetaStoreCache((HMSExternalCatalog) tbl.getCatalog());
HiveMetaStoreCache.HivePartitionValues hivePartitionValues = cache.getPartitionValues(
tbl, tbl.getPartitionColumnTypes(MvccUtil.getSnapshotFromContext(tbl)));
HiveMetaStoreCache.HivePartitionValues hivePartitionValues = tbl.getHivePartitionValues(
MvccUtil.getSnapshotFromContext(tbl));
Map<Long, List<String>> valuesMap = hivePartitionValues.getPartitionValuesMap();
List<TRow> dataBatch = Lists.newArrayList();
for (Map.Entry<Long, List<String>> entry : valuesMap.entrySet()) {
Expand Down
Loading