dutyu commented on code in PR #27666: URL: https://github.com/apache/doris/pull/27666#discussion_r1412728086
########## fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalMetaIdMgr.java: ########## @@ -0,0 +1,261 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.datasource; + +import org.apache.doris.catalog.Env; +import org.apache.doris.datasource.hive.event.MetastoreEventsProcessor; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Maps; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.Map; +import javax.annotation.Nullable; +import javax.validation.constraints.NotNull; + +/** + * <pre> + * ExternalMetaIdMgr is responsible for managing external meta ids. + * Now it just manages the external meta ids of hms events, + * but it will be extended to manage other external meta ids in the future. + * </pre> + * TODO: remove InitCatalogLog and InitDatabaseLog, manage external meta ids at ExternalMetaIdMgr + */ +public class ExternalMetaIdMgr { + + private static final Logger LOG = LogManager.getLogger(ExternalMetaIdMgr.class); + + private final Map<Long, CtlMetaIdMgr> idToCtlMgr = Maps.newConcurrentMap(); + + public ExternalMetaIdMgr() { + } + + // invoke this method only on master + public static long nextMetaId() { + return Env.getCurrentEnv().getNextId(); + } + + // return the db id of the specified db, -1 means not exists + public long getDbId(long catalogId, String dbName) { + DbMetaIdMgr dbMetaIdMgr = getDbMetaIdMgr(catalogId, dbName); + if (dbMetaIdMgr == null) { + return -1L; + } + return dbMetaIdMgr.dbId; + } + + // return the tbl id of the specified tbl, -1 means not exists + public long getTblId(long catalogId, String dbName, String tblName) { + TblMetaIdMgr tblMetaIdMgr = getTblMetaIdMgr(catalogId, dbName, tblName); + if (tblMetaIdMgr == null) { + return -1L; + } + return tblMetaIdMgr.tblId; + } + + // return the partition id of the specified partition, -1 means not exists + public long getPartitionId(long catalogId, String dbName, + String tblName, String partitionName) { + PartitionMetaIdMgr partitionMetaIdMgr = getPartitionMetaIdMgr(catalogId, dbName, tblName, partitionName); + if (partitionMetaIdMgr == null) { + return -1L; + } + return partitionMetaIdMgr.partitionId; + } + + public @Nullable DbMetaIdMgr getDbMetaIdMgr(long catalogId, String dbName) { + CtlMetaIdMgr ctlMetaIdMgr = idToCtlMgr.get(catalogId); + if (ctlMetaIdMgr == null) { + return null; + } + return ctlMetaIdMgr.dbNameToMgr.get(dbName); + } + + public @Nullable TblMetaIdMgr getTblMetaIdMgr(long catalogId, String dbName, String tblName) { Review Comment: done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org