This is an automated email from the ASF dual-hosted git repository.

morrysnow pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.1 by this push:
     new ed53f91ef97 branch-3.1: [Fix](create table) concurrent rename database 
causes table creation and replay failure #54614 (#56039)
ed53f91ef97 is described below

commit ed53f91ef97b6175e28a7805e1378c2da837f4ae
Author: deardeng <[email protected]>
AuthorDate: Wed Sep 17 17:01:55 2025 +0800

    branch-3.1: [Fix](create table) concurrent rename database causes table 
creation and replay failure #54614 (#56039)
    
    cherry pick from #54614
---
 .../src/main/java/org/apache/doris/catalog/Database.java   |  2 +-
 fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java |  3 ++-
 .../java/org/apache/doris/datasource/InternalCatalog.java  | 14 ++++++++++++--
 .../java/org/apache/doris/persist/CreateTableInfo.java     |  9 ++++++++-
 .../java/org/apache/doris/persist/CreateTableInfoTest.java |  2 +-
 5 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
index 1fb6cd28d6b..4bed1800162 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
@@ -428,7 +428,7 @@ public class Database extends MetaObject implements 
Writable, DatabaseIf<Table>,
                 registerTable(table);
                 if (!isReplay) {
                     // Write edit log
-                    CreateTableInfo info = new 
CreateTableInfo(fullQualifiedName, table);
+                    CreateTableInfo info = new 
CreateTableInfo(fullQualifiedName, id, table);
                     Env.getCurrentEnv().getEditLog().logCreateTable(info);
                 }
                 if (table.getType() == TableType.ELASTICSEARCH) {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
index 35e2f7b0637..89f757eb3a1 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
@@ -4330,7 +4330,8 @@ public class Env {
         if (Strings.isNullOrEmpty(info.getCtlName()) || info.getCtlName()
                 .equals(InternalCatalog.INTERNAL_CATALOG_NAME)) {
             Table table = info.getTable();
-            getInternalCatalog().replayCreateTable(info.getDbName(), table);
+            long dbId = info.getDbId();
+            getInternalCatalog().replayCreateTable(info.getDbName(), dbId, 
table);
             if (table instanceof MTMV) {
                 ((MTMV) table).compatible(Env.getCurrentEnv().getCatalogMgr());
             }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
index e571b18c2ae..612681f9013 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
@@ -1487,8 +1487,18 @@ public class InternalCatalog implements 
CatalogIf<Database> {
         }
     }
 
-    public void replayCreateTable(String dbName, Table table) throws 
MetaNotFoundException {
-        Database db = this.fullNameToDb.get(dbName);
+    public void replayCreateTable(String dbName, long dbId, Table table) 
throws MetaNotFoundException {
+        if (dbId != -1L) {
+            Database db = getDbOrMetaException(dbId);
+            replayCreateTableInternal(db, table);
+        } else {
+            // Compatible with old logic
+            Database db = getDbOrMetaException(dbName);
+            replayCreateTableInternal(db, table);
+        }
+    }
+
+    private void replayCreateTableInternal(Database db, Table table) throws 
MetaNotFoundException {
         try {
             db.createTableWithLock(table, true, false);
         } catch (DdlException e) {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/persist/CreateTableInfo.java 
b/fe/fe-core/src/main/java/org/apache/doris/persist/CreateTableInfo.java
index eab2f2b872e..82028b8c557 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/persist/CreateTableInfo.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/persist/CreateTableInfo.java
@@ -42,6 +42,8 @@ public class CreateTableInfo implements Writable, 
GsonPostProcessable {
 
     @SerializedName(value = "ctl")
     private String ctlName;
+    @SerializedName(value = "dbId")
+    private long dbId = -1L;
     @SerializedName(value = "dbName")
     private String dbName;
     @SerializedName(value = "tbl")
@@ -54,8 +56,9 @@ public class CreateTableInfo implements Writable, 
GsonPostProcessable {
     }
 
     // for internal table
-    public CreateTableInfo(String dbName, Table table) {
+    public CreateTableInfo(String dbName, long dbId, Table table) {
         this.ctlName = InternalCatalog.INTERNAL_CATALOG_NAME;
+        this.dbId = dbId;
         this.dbName = dbName;
         this.tblName = table.getName();
         this.table = table;
@@ -76,6 +79,10 @@ public class CreateTableInfo implements Writable, 
GsonPostProcessable {
         return dbName;
     }
 
+    public long getDbId() {
+        return dbId;
+    }
+
     public String getTblName() {
         return tblName;
     }
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/persist/CreateTableInfoTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/persist/CreateTableInfoTest.java
index 810e84592d9..d2cb6ad60fe 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/persist/CreateTableInfoTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/persist/CreateTableInfoTest.java
@@ -95,7 +95,7 @@ public class CreateTableInfoTest {
                 TStorageType.COLUMN, KeysType.AGG_KEYS);
         Deencapsulation.setField(table, "baseIndexId", 1000);
         table.addPartition(partition);
-        CreateTableInfo info = new CreateTableInfo("db1", table);
+        CreateTableInfo info = new CreateTableInfo("db1", -1L, table);
         info.write(dos);
 
         dos.flush();


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

Reply via email to