mymeiyi commented on code in PR #31893:
URL: https://github.com/apache/doris/pull/31893#discussion_r1618082274


##########
fe/fe-core/src/main/java/org/apache/doris/catalog/CatalogRecycleBin.java:
##########
@@ -907,6 +907,117 @@ public synchronized void replayRecoverPartition(OlapTable 
table, long partitionI
         }
     }
 
+    // erase database in catalog recycle bin instantly
+    public synchronized void eraseDatabaseInstantly(long dbId) throws 
DdlException {
+        // 1. find dbInfo to erase
+        RecycleDatabaseInfo dbInfo = idToDatabase.get(dbId);
+        if (dbInfo == null) {
+            throw new DdlException("Unknown database id '" + dbId + "'");
+        }
+
+        // 2. erase db
+        Env.getCurrentEnv().eraseDatabase(dbId, true);
+
+        // 3. erase db from idToDatabase and idToRecycleTime
+        idToDatabase.remove(dbId);
+        idToRecycleTime.remove(dbId);
+
+        // 4. log for erase db
+        String dbName = dbInfo.getDb().getName();
+        LOG.info("erase db[{}]: {}", dbId, dbName);
+
+        // 5. remove all tables with the same dbId
+        List<Long> tableIdToErase = Lists.newArrayList();
+        Iterator<Map.Entry<Long, RecycleTableInfo>> tableIterator = 
idToTable.entrySet().iterator();
+        while (tableIterator.hasNext()) {
+            Map.Entry<Long, RecycleTableInfo> entry = tableIterator.next();
+            RecycleTableInfo tableInfo = entry.getValue();
+            if (tableInfo.getDbId() == dbId) {
+                tableIdToErase.add(entry.getKey());
+            }
+        }
+        for (Long tableId : tableIdToErase) {
+            eraseTableInstantly(tableId);
+        }
+
+        // 6. remove all partitions with the same dbId
+        List<Long> partitionIdToErase = Lists.newArrayList();
+        Iterator<Map.Entry<Long, RecyclePartitionInfo>> partitionIterator = 
idToPartition.entrySet().iterator();
+        while (partitionIterator.hasNext()) {
+            Map.Entry<Long, RecyclePartitionInfo> entry = 
partitionIterator.next();
+            RecyclePartitionInfo partitionInfo = entry.getValue();
+            if (partitionInfo.getDbId() == dbId) {
+                partitionIdToErase.add(entry.getKey());
+            }
+        }
+        for (Long partitionId : partitionIdToErase) {
+            erasePartitionInstantly(partitionId);
+        }
+    }
+
+    // erase table in catalog recycle bin instantly
+    public synchronized void eraseTableInstantly(long tableId) throws 
DdlException {
+        // 1. find tableInfo to erase
+        RecycleTableInfo tableInfo = idToTable.get(tableId);
+        if (tableInfo == null) {
+            throw new DdlException("Unknown table id '" + tableId + "'");
+        }
+
+        // 2. erase table
+        long dbId = tableInfo.getDbId();
+        Table table = tableInfo.getTable();
+        if (table.getType() == TableType.OLAP || table.getType() == 
TableType.MATERIALIZED_VIEW) {

Review Comment:
   table.isManagedTable()



-- 
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