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

starocean999 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 820c9accd9d [fix](nereids)let query be able to forwarded to master 
(#40119)
820c9accd9d is described below

commit 820c9accd9d3747b8c4556f15e784e9627ab5b3f
Author: starocean999 <40539150+starocean...@users.noreply.github.com>
AuthorDate: Thu Sep 12 14:42:21 2024 +0800

    [fix](nereids)let query be able to forwarded to master (#40119)
    
    some times the follower's meta data is out of date. so we need forward
    the query to master until the meta data is sync with master
---
 .../main/java/org/apache/doris/qe/StmtExecutor.java | 21 +++++++++++++++++++++
 .../doris/nereids/preprocess/SelectHintTest.java    |  6 ++++++
 2 files changed, 27 insertions(+)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
index 5c1bc93bc71..c2247871017 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
@@ -787,6 +787,27 @@ public class StmtExecutor {
             }
         } else {
             context.getState().setIsQuery(true);
+            if (isForwardToMaster()) {
+                // some times the follower's meta data is out of date.
+                // so we need forward the query to master until the meta data 
is sync with master
+                if (context.getCommand() == MysqlCommand.COM_STMT_PREPARE) {
+                    throw new UserException("Forward master command is not 
supported for prepare statement");
+                }
+                if (isProxy) {
+                    // This is already a stmt forwarded from other FE.
+                    // If we goes here, means we can't find a valid Master 
FE(some error happens).
+                    // To avoid endless forward, throw exception here.
+                    throw new NereidsException(new UserException("The 
statement has been forwarded to master FE("
+                            + Env.getCurrentEnv().getSelfNode().getHost() + ") 
and failed to execute"
+                            + " because Master FE is not ready. You may need 
to check FE's status"));
+                }
+                redirectStatus = RedirectStatus.NO_FORWARD;
+                forwardToMaster();
+                if (masterOpExecutor != null && masterOpExecutor.getQueryId() 
!= null) {
+                    context.setQueryId(masterOpExecutor.getQueryId());
+                }
+                return;
+            }
             // create plan
             // Query following createting table would throw table not exist 
error.
             // For example.
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/preprocess/SelectHintTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/preprocess/SelectHintTest.java
index e936847053c..03b7e8dc366 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/preprocess/SelectHintTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/preprocess/SelectHintTest.java
@@ -47,6 +47,12 @@ public class SelectHintTest {
                 return ctx;
             }
         };
+        new MockUp<Env>() {
+            @Mock
+            public boolean isMaster() {
+                return true;
+            }
+        };
     }
 
     @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to