qidaye commented on a change in pull request #7391:
URL: https://github.com/apache/incubator-doris/pull/7391#discussion_r790684457



##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/external/iceberg/IcebergTableCreationRecordMgr.java
##########
@@ -0,0 +1,232 @@
+// 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.external.iceberg;
+
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.IcebergProperty;
+import org.apache.doris.catalog.IcebergTable;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.property.PropertySchema;
+import org.apache.doris.common.util.MasterDaemon;
+
+import com.google.common.collect.Maps;
+
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.PriorityQueue;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ * Manager for Iceberg automatic creation table records
+ * used to create iceberg tables and show table creation records
+ */
+public class IcebergTableCreationRecordMgr extends MasterDaemon {
+    private static final Logger LOG = 
LogManager.getLogger(IcebergTableCreationRecordMgr.class);
+
+    private static final String SUCCESS = "success";
+    private static final String FAIL = "fail";
+
+    // database -> table identifier -> properties
+    // used to create table
+    private Map<Database, Map<TableIdentifier, IcebergProperty>> 
dbToTableIdentifiers = Maps.newConcurrentMap();
+    // table creation records, used for show stmt
+    // db -> table -> create msg
+    private Map<String, Map<String, IcebergTableCreationRecord>> 
dbToTableToCreationRecord = Maps.newConcurrentMap();
+
+    private Queue<IcebergTableCreationRecord> tableCreationRecordQueue = new 
PriorityQueue<>(new TableCreationComparator());
+    private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+
+
+    public IcebergTableCreationRecordMgr() {
+        super("iceberg_table_creation_record_mgr", 
Config.iceberg_table_creation_interval_second * 1000);
+    }
+
+    public void registerTable(Database db, TableIdentifier identifier, 
IcebergProperty icebergProperty) {
+        if (dbToTableIdentifiers.containsKey(db)) {
+            dbToTableIdentifiers.get(db).put(identifier, icebergProperty);
+        } else {
+            Map<TableIdentifier, IcebergProperty> identifierToProperties = 
Maps.newConcurrentMap();
+            identifierToProperties.put(identifier, icebergProperty);
+            dbToTableIdentifiers.put(db, identifierToProperties);
+        }
+        LOG.info("Register a new table[{}] to database[{}]", 
identifier.name(), db.getFullName());
+    }
+
+    public void deregisterdb(Database db) {
+        dbToTableIdentifiers.remove(db);
+        dbToTableToCreationRecord.remove(db.getFullName());
+        LOG.info("DeRegister database[{}]", db.getFullName());
+    }
+
+    public void deregisterTable(Database db, IcebergTable table) {
+        if (dbToTableIdentifiers.containsKey(db)) {
+            TableIdentifier identifier = 
TableIdentifier.of(table.getIcebergDb(), table.getIcebergTbl());
+            Map<TableIdentifier, IcebergProperty> identifierToProperties = 
dbToTableIdentifiers.get(db);
+            identifierToProperties.remove(identifier);
+        }
+        if (dbToTableToCreationRecord.containsKey(db.getFullName())) {
+            Map<String, IcebergTableCreationRecord> recordMap = 
dbToTableToCreationRecord.get(db.getFullName());
+            recordMap.remove(table.getName());
+        }
+        LOG.info("DeRegister table[{}] from database[{}]", table.getName(), 
db.getFullName());

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

Reply via email to