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 9ffacace227 branch-3.1: [fix](catalog) fix deadlock of catalog and 
database #53626 (#53627)
9ffacace227 is described below

commit 9ffacace227d7af5c203919440894ce39abe6c9f
Author: Mingyu Chen (Rayner) <[email protected]>
AuthorDate: Tue Jul 22 19:29:36 2025 -0700

    branch-3.1: [fix](catalog) fix deadlock of catalog and database #53626 
(#53627)
    
    bp #53626
---
 .../apache/doris/datasource/ExternalDatabase.java  | 66 ++++++++++++----------
 1 file changed, 35 insertions(+), 31 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalDatabase.java 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalDatabase.java
index ef6a42ac49d..b7a73505b68 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalDatabase.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalDatabase.java
@@ -158,41 +158,45 @@ public abstract class ExternalDatabase<T extends 
ExternalTable>
         return initialized;
     }
 
-    public final synchronized void makeSureInitialized() {
-        if (isInitializing) {
-            return;
-        }
-        isInitializing = true;
-        try {
-            extCatalog.makeSureInitialized();
-            if (!initialized) {
-                if (extCatalog.getUseMetaCache().get()) {
-                    buildMetaCache();
-                    setLastUpdateTime(System.currentTimeMillis());
-                } else {
-                    if (!Env.getCurrentEnv().isMaster()) {
-                        // Forward to master and wait the journal to replay.
-                        int waitTimeOut = ConnectContext.get() == null ? 300 : 
ConnectContext.get().getExecTimeout();
-                        MasterCatalogExecutor remoteExecutor = new 
MasterCatalogExecutor(waitTimeOut * 1000);
-                        try {
-                            remoteExecutor.forward(extCatalog.getId(), id);
-                        } catch (Exception e) {
-                            Util.logAndThrowRuntimeException(LOG,
-                                    String.format("failed to forward init 
external db %s operation to master", name),
-                                    e);
+    public final void makeSureInitialized() {
+        // Must call this method before any operation on the database to avoid 
deadlock of synchronized block
+        extCatalog.makeSureInitialized();
+        synchronized (this) {
+            if (isInitializing) {
+                return;
+            }
+            isInitializing = true;
+            try {
+                if (!initialized) {
+                    if (extCatalog.getUseMetaCache().get()) {
+                        buildMetaCache();
+                        setLastUpdateTime(System.currentTimeMillis());
+                    } else {
+                        if (!Env.getCurrentEnv().isMaster()) {
+                            // Forward to master and wait the journal to 
replay.
+                            int waitTimeOut = ConnectContext.get() == null ? 
300
+                                    : ConnectContext.get().getExecTimeout();
+                            MasterCatalogExecutor remoteExecutor = new 
MasterCatalogExecutor(waitTimeOut * 1000);
+                            try {
+                                remoteExecutor.forward(extCatalog.getId(), id);
+                            } catch (Exception e) {
+                                Util.logAndThrowRuntimeException(LOG,
+                                        String.format("failed to forward init 
external db %s operation to master",
+                                                name), e);
+                            }
+                            return;
                         }
-                        return;
+                        init();
                     }
-                    init();
+                    initialized = true;
                 }
-                initialized = true;
+            } catch (Exception e) {
+                LOG.warn("failed to init db {}, id {}, isInitializing: {}, 
initialized: {}",
+                        this.name, this.id, isInitializing, initialized, e);
+                initialized = false;
+            } finally {
+                isInitializing = false;
             }
-        } catch (Exception e) {
-            LOG.warn("failed to init db {}, id {}, isInitializing: {}, 
initialized: {}",
-                    this.name, this.id, isInitializing, initialized, e);
-            initialized = false;
-        } finally {
-            isInitializing = false;
         }
     }
 


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

Reply via email to