1717
1818package org .apache .doris .datasource .metacache ;
1919
20+ import org .apache .doris .datasource .CatalogScopedCacheMgr ;
2021import org .apache .doris .datasource .ExternalCatalog ;
2122import org .apache .doris .datasource .ExternalTable ;
2223import org .apache .doris .datasource .SchemaCacheValue ;
24+ import org .apache .doris .datasource .hive .HMSExternalCatalog ;
2325import org .apache .doris .datasource .hive .HMSExternalTable ;
2426import org .apache .doris .datasource .hive .HiveEngineCache ;
27+ import org .apache .doris .datasource .hive .HiveMetaStoreCache ;
28+ import org .apache .doris .datasource .hudi .source .HudiCachedPartitionProcessor ;
2529import org .apache .doris .datasource .hudi .source .HudiEngineCache ;
30+ import org .apache .doris .datasource .hudi .source .HudiMetadataCacheMgr ;
2631import org .apache .doris .datasource .iceberg .IcebergEngineCache ;
2732import org .apache .doris .datasource .iceberg .IcebergExternalTable ;
33+ import org .apache .doris .datasource .iceberg .IcebergMetadataCache ;
2834import org .apache .doris .datasource .maxcompute .MaxComputeEngineCache ;
2935import org .apache .doris .datasource .maxcompute .MaxComputeExternalTable ;
36+ import org .apache .doris .datasource .maxcompute .MaxComputeMetadataCacheMgr ;
3037import org .apache .doris .datasource .paimon .PaimonEngineCache ;
3138import org .apache .doris .datasource .paimon .PaimonExternalTable ;
39+ import org .apache .doris .datasource .paimon .PaimonMetadataCache ;
3240
3341import com .google .common .collect .ImmutableSet ;
3442
3846import java .util .Optional ;
3947import java .util .Set ;
4048import java .util .concurrent .ConcurrentHashMap ;
49+ import java .util .concurrent .ExecutorService ;
4150import java .util .function .Consumer ;
4251import java .util .function .Function ;
4352
@@ -48,6 +57,41 @@ public class UnifiedMetaCacheMgr {
4857 private final Map <Long , CatalogMetaCache > catalogMetaCaches = new ConcurrentHashMap <>();
4958 private final Map <String , Function <ExternalCatalog , ? extends EngineMetaCache >> engineFactories =
5059 new ConcurrentHashMap <>();
60+ private final CatalogScopedCacheMgr <HiveMetaStoreCache > hiveMetaStoreCacheMgr ;
61+ private final CatalogScopedCacheMgr <IcebergMetadataCache > icebergMetadataCacheMgr ;
62+ private final CatalogScopedCacheMgr <PaimonMetadataCache > paimonMetadataCacheMgr ;
63+ private final HudiMetadataCacheMgr hudiMetadataCacheMgr ;
64+ private final MaxComputeMetadataCacheMgr maxComputeMetadataCacheMgr ;
65+
66+ public UnifiedMetaCacheMgr (ExecutorService commonRefreshExecutor , ExecutorService fileListingExecutor ) {
67+ Objects .requireNonNull (commonRefreshExecutor , "commonRefreshExecutor cannot be null" );
68+ Objects .requireNonNull (fileListingExecutor , "fileListingExecutor cannot be null" );
69+
70+ hudiMetadataCacheMgr = new HudiMetadataCacheMgr (commonRefreshExecutor );
71+ maxComputeMetadataCacheMgr = new MaxComputeMetadataCacheMgr ();
72+ hiveMetaStoreCacheMgr = new CatalogScopedCacheMgr <>(
73+ catalog -> new HiveMetaStoreCache ((HMSExternalCatalog ) catalog ,
74+ commonRefreshExecutor , fileListingExecutor ));
75+ icebergMetadataCacheMgr = new CatalogScopedCacheMgr <>(
76+ catalog -> new IcebergMetadataCache (catalog , commonRefreshExecutor ));
77+ paimonMetadataCacheMgr = new CatalogScopedCacheMgr <>(
78+ catalog -> new PaimonMetadataCache (catalog , commonRefreshExecutor ));
79+
80+ registerEngineFactory (PaimonEngineCache .ENGINE_TYPE ,
81+ catalog -> new PaimonEngineCache (paimonMetadataCacheMgr .getCache (catalog )));
82+ registerEngineFactory (IcebergEngineCache .ENGINE_TYPE ,
83+ catalog -> new IcebergEngineCache (icebergMetadataCacheMgr .getCache (catalog )));
84+ registerEngineFactory (MaxComputeEngineCache .ENGINE_TYPE ,
85+ catalog -> new MaxComputeEngineCache (
86+ maxComputeMetadataCacheMgr .getMaxComputeMetadataCache (catalog )));
87+ registerEngineFactory (HiveEngineCache .ENGINE_TYPE ,
88+ catalog -> new HiveEngineCache (hiveMetaStoreCacheMgr .getCache (catalog )));
89+ registerEngineFactory (HudiEngineCache .ENGINE_TYPE ,
90+ catalog -> new HudiEngineCache (
91+ (HudiCachedPartitionProcessor ) hudiMetadataCacheMgr .getPartitionProcessor (catalog ),
92+ hudiMetadataCacheMgr .getFsViewProcessor (catalog ),
93+ hudiMetadataCacheMgr .getHudiMetaClientProcessor (catalog )));
94+ }
5195
5296 public void registerEngineFactory (String engineType ,
5397 Function <ExternalCatalog , ? extends EngineMetaCache > engineFactory ) {
@@ -123,6 +167,7 @@ public CatalogMetaCache removeCatalogMetaCache(long catalogId) {
123167 if (catalogMetaCache != null ) {
124168 catalogMetaCache .invalidateCatalog ();
125169 }
170+ removeCatalogBackingCaches (catalogId );
126171 return catalogMetaCache ;
127172 }
128173
@@ -215,6 +260,17 @@ private ExternalCatalog requireCatalog(ExternalTable table) {
215260 return Objects .requireNonNull (table .getCatalog (), "table catalog cannot be null" );
216261 }
217262
263+ private void removeCatalogBackingCaches (long catalogId ) {
264+ hiveMetaStoreCacheMgr .removeCache (catalogId );
265+ icebergMetadataCacheMgr .removeCache (catalogId );
266+ hudiMetadataCacheMgr .removeCache (catalogId );
267+ maxComputeMetadataCacheMgr .removeCache (catalogId );
268+ PaimonMetadataCache paimonMetadataCache = paimonMetadataCacheMgr .removeCache (catalogId );
269+ if (paimonMetadataCache != null ) {
270+ paimonMetadataCache .invalidateCatalogCache (catalogId );
271+ }
272+ }
273+
218274 private void withCatalogMetaCache (long catalogId , Consumer <CatalogMetaCache > consumer ) {
219275 CatalogMetaCache catalogMetaCache = catalogMetaCaches .get (catalogId );
220276 if (catalogMetaCache != null ) {
0 commit comments