|
| 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 | +} |
0 commit comments