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

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 8da1b5569e378aeee45440e1720fb2098f53187a
Author: Mingyu Chen <[email protected]>
AuthorDate: Wed Mar 15 20:50:29 2023 +0800

    [fix](multi-catalog) fix forward to master throw NPE (#17791)
    
    The ConnectionContext maybe null, and actually, we don't need 
ConnectionContext in MasterCatalogExecutor
---
 .../doris/catalog/external/ExternalDatabase.java      |  5 ++++-
 .../org/apache/doris/datasource/ExternalCatalog.java  |  6 +++++-
 .../org/apache/doris/qe/MasterCatalogExecutor.java    | 19 ++++++-------------
 3 files changed, 15 insertions(+), 15 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/catalog/external/ExternalDatabase.java
 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/external/ExternalDatabase.java
index e4efcac408..4a6c43cf22 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/catalog/external/ExternalDatabase.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/external/ExternalDatabase.java
@@ -110,7 +110,9 @@ public class ExternalDatabase<T extends ExternalTable> 
implements DatabaseIf<T>,
         if (!initialized) {
             if (!Env.getCurrentEnv().isMaster()) {
                 // Forward to master and wait the journal to replay.
-                MasterCatalogExecutor remoteExecutor = new 
MasterCatalogExecutor();
+                int waitTimeOut = ConnectContext.get() == null ? 300 : 
ConnectContext.get().getSessionVariable()
+                        .getQueryTimeoutS();
+                MasterCatalogExecutor remoteExecutor = new 
MasterCatalogExecutor(waitTimeOut * 1000);
                 try {
                     remoteExecutor.forward(extCatalog.getId(), id);
                 } catch (Exception e) {
@@ -268,3 +270,4 @@ public class ExternalDatabase<T extends ExternalTable> 
implements DatabaseIf<T>,
         throw new NotImplementedException();
     }
 }
+
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java
index e33c8fa58e..3cdf009182 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java
@@ -32,6 +32,7 @@ import org.apache.doris.common.io.Writable;
 import org.apache.doris.common.util.Util;
 import org.apache.doris.persist.gson.GsonPostProcessable;
 import org.apache.doris.persist.gson.GsonUtils;
+import org.apache.doris.qe.ConnectContext;
 import org.apache.doris.qe.MasterCatalogExecutor;
 
 import com.google.common.collect.Lists;
@@ -123,7 +124,9 @@ public abstract class ExternalCatalog implements 
CatalogIf<ExternalDatabase>, Wr
         if (!initialized) {
             if (!Env.getCurrentEnv().isMaster()) {
                 // Forward to master and wait the journal to replay.
-                MasterCatalogExecutor remoteExecutor = new 
MasterCatalogExecutor();
+                int waitTimeOut = ConnectContext.get() == null ? 300
+                        : 
ConnectContext.get().getSessionVariable().getQueryTimeoutS();
+                MasterCatalogExecutor remoteExecutor = new 
MasterCatalogExecutor(waitTimeOut * 1000);
                 try {
                     remoteExecutor.forward(id, -1);
                 } catch (Exception e) {
@@ -373,3 +376,4 @@ public abstract class ExternalCatalog implements 
CatalogIf<ExternalDatabase>, Wr
         throw new NotImplementedException();
     }
 }
+
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/qe/MasterCatalogExecutor.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/MasterCatalogExecutor.java
index e13d2daefd..7fd3322d60 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/MasterCatalogExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/MasterCatalogExecutor.java
@@ -17,6 +17,7 @@
 
 package org.apache.doris.qe;
 
+import org.apache.doris.catalog.Env;
 import org.apache.doris.common.ClientPool;
 import org.apache.doris.thrift.FrontendService;
 import org.apache.doris.thrift.TInitExternalCtlMetaRequest;
@@ -32,28 +33,20 @@ import org.apache.logging.log4j.Logger;
  * This client will wait for the journal ID replayed at this Observer FE 
before return.
  */
 public class MasterCatalogExecutor {
-
     private static final Logger LOG = 
LogManager.getLogger(MasterCatalogExecutor.class);
 
-    private final ConnectContext ctx;
     private int waitTimeoutMs;
 
-    public MasterCatalogExecutor() {
-        ctx = ConnectContext.get();
-        if (ctx == null) {
-            // The method may be called by FrontendServiceImpl from BE, which 
does not have ConnectContext.
-            waitTimeoutMs = 300 * 1000;
-        } else {
-            waitTimeoutMs = ctx.getSessionVariable().getQueryTimeoutS() * 1000;
-        }
+    public MasterCatalogExecutor(int waitTimeoutMs) {
+        this.waitTimeoutMs = waitTimeoutMs;
     }
 
     public void forward(long catalogId, long dbId) throws Exception {
-        if (!ctx.getEnv().isReady()) {
+        if (!Env.getCurrentEnv().isReady()) {
             throw new Exception("Current catalog is not ready, please wait for 
a while.");
         }
-        String masterHost = ctx.getEnv().getMasterIp();
-        int masterRpcPort = ctx.getEnv().getMasterRpcPort();
+        String masterHost = Env.getCurrentEnv().getMasterIp();
+        int masterRpcPort = Env.getCurrentEnv().getMasterRpcPort();
         TNetworkAddress thriftAddress = new TNetworkAddress(masterHost, 
masterRpcPort);
 
         FrontendService.Client client = null;


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

Reply via email to