nooneuse commented on code in PR #66307:
URL: https://github.com/apache/doris/pull/66307#discussion_r3882558084


##########
fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java:
##########
@@ -616,50 +628,64 @@ public void recoverDatabase(String dbName, long dbId, 
String newDbName) throws D
             }
         }
 
-        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);
+        ConstraintManager constraintManager = 
Env.getCurrentEnv().getConstraintManager();
+        boolean frontendAdmissionAcquired = false;
         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
+            frontendAdmissionAcquired = 
constraintManager.acquireFrontendAdmissionFence();
+            Database db = Env.getCurrentRecycleBin().recoverDatabase(dbName, 
dbId);
+            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
+                    }
                 }
-            } 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)) {
+                    db.setNameWithLock(newDbName);
                 }
+                fullNameToDb.put(db.getFullName(), db);
+                idToDb.put(db.getId(), db);
+                for (Table table : tableList) {
+                    constraintManager.restoreTableConstraints(
+                            TableNameInfoUtils.fromDb(db, table.getName()), 
table);
+                }
+                // log
+                RecoverInfo recoverInfo = new RecoverInfo(db.getId(), -1L, 
-1L, newDbName, "", "", "", "");
+                Env.getCurrentEnv().getEditLog().logRecoverDb(recoverInfo);
+                db.unmarkDropped();
+                registerDbFunctionsToNereids(db);
+                LOG.info("recover database[{}]", db.getId());
+            } finally {
+                MetaLockUtils.writeUnlockTables(tableList);
+                db.writeUnlock();
             }
-            if (!Strings.isNullOrEmpty(newDbName)) {
-                db.setNameWithLock(newDbName);
-            }
-            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();
-            registerDbFunctionsToNereids(db);
         } finally {
-            MetaLockUtils.writeUnlockTables(tableList);
-            db.writeUnlock();
+            if (frontendAdmissionAcquired) {
+                constraintManager.releaseFrontendAdmissionFence();
+            }
             unlock();
         }
-        LOG.info("recover database[{}]", db.getId());
     }
 
     public void recoverTable(String dbName, String tableName, String 
newTableName, long tableId) throws DdlException {
         Database db = getDbOrDdlException(dbName);
         db.writeLockOrDdlException();
+        ConstraintManager constraintManager = 
Env.getCurrentEnv().getConstraintManager();
+        boolean frontendAdmissionAcquired = 
constraintManager.acquireFrontendAdmissionFence();

Review Comment:
   okay



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to