Skip to content

Commit d57eb8a

Browse files
committed
Unify hudi/maxcompute meta caches under catalog scope
1 parent 36b91bb commit d57eb8a

File tree

6 files changed

+126
-259
lines changed

6 files changed

+126
-259
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.doris.datasource.hudi.source;
19+
20+
import org.apache.doris.common.Config;
21+
import org.apache.doris.datasource.ExternalCatalog;
22+
import org.apache.doris.datasource.hive.HMSExternalCatalog;
23+
import org.apache.doris.datasource.metacache.CacheSpec;
24+
25+
import java.util.Objects;
26+
import java.util.concurrent.ExecutorService;
27+
28+
/**
29+
* Per-catalog cache container for Hudi metadata processors.
30+
*/
31+
public final class HudiCatalogCache {
32+
private static final String PARTITION_MODULE_NAME = "partition";
33+
private static final String FS_VIEW_MODULE_NAME = "fs-view";
34+
private static final String META_CLIENT_MODULE_NAME = "meta-client";
35+
36+
private final HudiCachedPartitionProcessor partitionProcessor;
37+
private final HudiCachedFsViewProcessor fsViewProcessor;
38+
private final HudiCachedMetaClientProcessor metaClientProcessor;
39+
40+
private HudiCatalogCache(HudiCachedPartitionProcessor partitionProcessor,
41+
HudiCachedFsViewProcessor fsViewProcessor,
42+
HudiCachedMetaClientProcessor metaClientProcessor) {
43+
this.partitionProcessor = Objects.requireNonNull(partitionProcessor, "partitionProcessor cannot be null");
44+
this.fsViewProcessor = Objects.requireNonNull(fsViewProcessor, "fsViewProcessor cannot be null");
45+
this.metaClientProcessor = Objects.requireNonNull(metaClientProcessor, "metaClientProcessor cannot be null");
46+
}
47+
48+
public static HudiCatalogCache fromCatalog(ExternalCatalog catalog, ExecutorService executor) {
49+
Objects.requireNonNull(catalog, "catalog cannot be null");
50+
Objects.requireNonNull(executor, "executor cannot be null");
51+
if (!(catalog instanceof HMSExternalCatalog)) {
52+
throw new IllegalArgumentException("Hudi only supports hive(or compatible) catalog now");
53+
}
54+
HudiCachedPartitionProcessor partitionProcessor = new HudiCachedPartitionProcessor(catalog.getId(), executor,
55+
resolveCacheSpec(catalog, PARTITION_MODULE_NAME));
56+
HudiCachedFsViewProcessor fsViewProcessor = new HudiCachedFsViewProcessor(executor,
57+
resolveCacheSpec(catalog, FS_VIEW_MODULE_NAME));
58+
HudiCachedMetaClientProcessor metaClientProcessor = new HudiCachedMetaClientProcessor(executor,
59+
resolveCacheSpec(catalog, META_CLIENT_MODULE_NAME));
60+
return new HudiCatalogCache(partitionProcessor, fsViewProcessor, metaClientProcessor);
61+
}
62+
63+
public HudiCachedPartitionProcessor getPartitionProcessor() {
64+
return partitionProcessor;
65+
}
66+
67+
public HudiCachedFsViewProcessor getFsViewProcessor() {
68+
return fsViewProcessor;
69+
}
70+
71+
public HudiCachedMetaClientProcessor getMetaClientProcessor() {
72+
return metaClientProcessor;
73+
}
74+
75+
public void cleanUp() {
76+
partitionProcessor.cleanUp();
77+
fsViewProcessor.cleanUp();
78+
metaClientProcessor.cleanUp();
79+
}
80+
81+
private static CacheSpec resolveCacheSpec(ExternalCatalog catalog, String moduleName) {
82+
return CacheSpec.fromUnifiedProperties(catalog.getProperties(), HudiEngineCache.ENGINE_TYPE, moduleName, true,
83+
Config.external_cache_expire_time_seconds_after_access, Config.max_external_table_cache_num);
84+
}
85+
}

fe/fe-core/src/main/java/org/apache/doris/datasource/hudi/source/HudiMetadataCacheMgr.java

Lines changed: 0 additions & 160 deletions
This file was deleted.

fe/fe-core/src/main/java/org/apache/doris/datasource/maxcompute/MaxComputeMetadataCache.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.doris.datasource.maxcompute;
1919

2020
import org.apache.doris.common.Config;
21+
import org.apache.doris.datasource.ExternalCatalog;
2122
import org.apache.doris.datasource.TablePartitionValues;
2223
import org.apache.doris.datasource.metacache.CacheSpec;
2324

@@ -26,11 +27,13 @@
2627
import com.github.benmanes.caffeine.cache.stats.CacheStats;
2728

2829
import java.util.List;
30+
import java.util.Objects;
2931
import java.util.concurrent.TimeUnit;
3032
import java.util.function.Function;
3133
import java.util.stream.Collectors;
3234

3335
public class MaxComputeMetadataCache {
36+
private static final String PARTITION_VALUES_MODULE_NAME = "partition-values";
3437
private final Cache<MaxComputeCacheKey, TablePartitionValues> partitionValuesCache;
3538

3639
public MaxComputeMetadataCache(CacheSpec cacheSpec) {
@@ -46,10 +49,18 @@ public MaxComputeMetadataCache(CacheSpec cacheSpec) {
4649

4750
public MaxComputeMetadataCache() {
4851
this(CacheSpec.fromUnifiedProperties(java.util.Collections.emptyMap(),
49-
MaxComputeEngineCache.ENGINE_TYPE, "partition-values", true,
52+
MaxComputeEngineCache.ENGINE_TYPE, PARTITION_VALUES_MODULE_NAME, true,
5053
Config.external_cache_expire_time_seconds_after_access, Config.max_hive_partition_cache_num));
5154
}
5255

56+
public static MaxComputeMetadataCache fromCatalog(ExternalCatalog catalog) {
57+
Objects.requireNonNull(catalog, "catalog cannot be null");
58+
CacheSpec cacheSpec = CacheSpec.fromUnifiedProperties(catalog.getProperties(),
59+
MaxComputeEngineCache.ENGINE_TYPE, PARTITION_VALUES_MODULE_NAME, true,
60+
Config.external_cache_expire_time_seconds_after_access, Config.max_hive_partition_cache_num);
61+
return new MaxComputeMetadataCache(cacheSpec);
62+
}
63+
5364
public TablePartitionValues getCachedPartitionValues(MaxComputeCacheKey tablePartitionKey,
5465
Function<? super MaxComputeCacheKey, ? extends TablePartitionValues> loader) {
5566
return partitionValuesCache.get(tablePartitionKey, loader);

fe/fe-core/src/main/java/org/apache/doris/datasource/maxcompute/MaxComputeMetadataCacheMgr.java

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)