Vallishp commented on code in PR #42946:
URL: https://github.com/apache/doris/pull/42946#discussion_r1827183301


##########
fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java:
##########
@@ -601,6 +601,63 @@ public void replayDropDb(String dbName, boolean 
isForceDrop, Long recycleTime) t
         }
     }
 
+    public void recoverDatabase(String dbName, long dbId, String newDbName) 
throws DdlException {
+        // check is new db with same name already exist
+        if (!Strings.isNullOrEmpty(newDbName)) {
+            if (getDb(newDbName).isPresent()) {
+                throw new DdlException("Database[" + newDbName + "] already 
exist.");
+            }
+        } else {
+            if (getDb(dbName).isPresent()) {
+                throw new DdlException("Database[" + dbName + "] already 
exist.");
+            }
+        }
+
+        Database db = Env.getCurrentRecycleBin().recoverDatabase(dbName, dbId);
+
+        // add db to catalog
+        if (!tryLock(false)) {
+            throw new DdlException("Failed to acquire catalog lock. Try 
again");
+        }
+        db.writeLock();
+        List<Table> tableList = db.getTablesOnIdOrder();
+        MetaLockUtils.writeLockTables(tableList);
+        try {
+            if (!Strings.isNullOrEmpty(newDbName)) {
+                if (fullNameToDb.containsKey(newDbName)) {
+                    throw new DdlException("Database[" + newDbName + "] 
already exist.");
+                    // it's ok that we do not put db back to CatalogRecycleBin
+                    // cause this db cannot recover any more
+                }
+            } else {
+                if (fullNameToDb.containsKey(db.getFullName())) {
+                    throw new DdlException("Database[" + db.getFullName() + "] 
already exist.");
+                    // it's ok that we do not put db back to CatalogRecycleBin
+                    // cause this db cannot recover any more
+                }
+            }
+            if (!Strings.isNullOrEmpty(newDbName)) {
+                try {
+                    db.writeUnlock();
+                    db.setNameWithLock(newDbName);
+                } finally {
+                    db.writeLock();
+                }
+            }
+            fullNameToDb.put(db.getFullName(), db);
+            idToDb.put(db.getId(), db);
+            // log
+            RecoverInfo recoverInfo = new RecoverInfo(db.getId(), -1L, -1L, 
newDbName, "", "");
+            Env.getCurrentEnv().getEditLog().logRecoverDb(recoverInfo);
+            db.unmarkDropped();
+        } finally {
+            MetaLockUtils.writeUnlockTables(tableList);
+            db.writeUnlock();
+            unlock();
+        }
+        LOG.info("recover database[{}]", db.getId());
+    }
+
     public void recoverDatabase(RecoverDbStmt recoverStmt) throws DdlException 
{
         // check is new db with same name already exist
         String newDbName = recoverStmt.getNewDbName();

Review Comment:
   thanks have handled it



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