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

dataroaring pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new d57dd6ffcf1 [fix](table) Fix create table and drop partition race 
(#55007)
d57dd6ffcf1 is described below

commit d57dd6ffcf1cbf594f1912316d411f71120d5667
Author: deardeng <[email protected]>
AuthorDate: Sun Aug 24 16:30:13 2025 +0800

    [fix](table) Fix create table and drop partition race (#55007)
    
    ### What problem does this PR solve?
    
    Fix
    Step 1. create table include partitions, table's partitions has been add
    to map (leak table lock), write editlog1
    Step 2. drop partition, write editlog2
    Setp 3. first replay editlog2, then replay editlog1, editlog1 toSql()
    find patition by partitionId, can't find, npe
    
    ```
    2025-08-15 17:39:48,792 ERROR (replayer|113) [EditLog.loadJournal():1443] 
replay Operation Type 10, log id: 363
    java.lang.NullPointerException: Cannot invoke 
"org.apache.doris.catalog.Partition.getName()" because "partition" is null
            at 
org.apache.doris.catalog.ListPartitionInfo.toSql(ListPartitionInfo.java:164) 
~[doris-fe.jar:1.2-SNAPSHOT]
            at org.apache.doris.catalog.Env.getDdlStmt(Env.java:4468) 
~[doris-fe.jar:1.2-SNAPSHOT]
            at org.apache.doris.catalog.Env.getSyncedDdlStmt(Env.java:3575) 
~[doris-fe.jar:1.2-SNAPSHOT]
            at 
org.apache.doris.binlog.CreateTableRecord.<init>(CreateTableRecord.java:83) 
~[doris-fe.jar:1.2-SNAPSHOT]
            at org.apache.doris.persist.EditLog.loadJournal(EditLog.java:357) 
~[doris-fe.jar:1.2-SNAPSHOT]
            at org.apache.doris.catalog.Env.replayJournal(Env.java:3113) 
~[doris-fe.jar:1.2-SNAPSHOT]
            at org.apache.doris.catalog.Env$4.runOneCycle(Env.java:2875) 
~[doris-fe.jar:1.2-SNAPSHOT]
            at org.apache.doris.common.util.Daemon.run(Daemon.java:119) 
~[doris-fe.jar:1.2-SNAPSHOT]
    ```
    
    
    
    Co-authored-by: Yongqiang YANG <[email protected]>
---
 .../java/org/apache/doris/catalog/Database.java    | 27 +++++++++++++---------
 1 file changed, 16 insertions(+), 11 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 052019a3a59..ebdbc03c0df 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
@@ -411,17 +411,22 @@ public class Database extends MetaObject implements 
Writable, DatabaseIf<Table>,
                 result = setIfNotExist;
                 isTableExist = true;
             } else {
-                registerTable(table);
-                if (table.isTemporary()) {
-                    Env.getCurrentEnv().registerTempTableAndSession(table);
-                }
-                if (table instanceof MTMV) {
-                    Env.getCurrentEnv().getMtmvService().createJob((MTMV) 
table, isReplay);
-                }
-                if (!isReplay) {
-                    // Write edit log
-                    CreateTableInfo info = new 
CreateTableInfo(fullQualifiedName, id, table);
-                    Env.getCurrentEnv().getEditLog().logCreateTable(info);
+                table.writeLock();
+                try {
+                    registerTable(table);
+                    if (table.isTemporary()) {
+                        Env.getCurrentEnv().registerTempTableAndSession(table);
+                    }
+                    if (table instanceof MTMV) {
+                        Env.getCurrentEnv().getMtmvService().createJob((MTMV) 
table, isReplay);
+                    }
+                    if (!isReplay) {
+                        // Write edit log
+                        CreateTableInfo info = new 
CreateTableInfo(fullQualifiedName, id, table);
+                        Env.getCurrentEnv().getEditLog().logCreateTable(info);
+                    }
+                } finally {
+                    table.writeUnlock();
                 }
                 if (table.getType() == TableType.ELASTICSEARCH) {
                     
Env.getCurrentEnv().getEsRepository().registerTable((EsTable) table);


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

Reply via email to