Skip to content

Commit

Permalink
[fix](readconsistency) avoid table not exist error apache#37593
Browse files Browse the repository at this point in the history
  • Loading branch information
dataroaring committed Jul 12, 2024
1 parent b2f9fde commit 95484da
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,13 @@ private void executeByNereids(TUniqueId queryId) throws Exception {
return;
}
}
// Query following createting table would throw table not exist error.
// For example.
// t1: client issues create table to master fe
// t2: client issues query sql to observer fe, the query would fail due to not exist table in
// plan phase.
// t3: observer fe receive editlog creating the table from the master fe
syncJournalIfNeeded();
try {
((Command) logicalPlan).run(context, this);
} catch (QueryStateException e) {
Expand All @@ -611,6 +618,13 @@ private void executeByNereids(TUniqueId queryId) throws Exception {
ConnectContext.get().setStatsErrorEstimator(new StatsErrorEstimator());
}
// create plan
// Query following createting table would throw table not exist error.
// For example.
// t1: client issues create table to master fe
// t2: client issues query sql to observer fe, the query would fail due to not exist table in
// plan phase.
// t3: observer fe receive editlog creating the table from the master fe
syncJournalIfNeeded();
planner = new NereidsPlanner(statementContext);
try {
planner.plan(parsedStmt, context.getSessionVariable().toThrift());
Expand Down Expand Up @@ -643,7 +657,6 @@ private void parseByNereids() {

private void handleQueryWithRetry(TUniqueId queryId) throws Exception {
// queue query here
syncJournalIfNeeded();
QueueOfferToken offerRet = null;
QueryQueue queryQueue = null;
if (!parsedStmt.isExplain() && Config.enable_workload_group && Config.enable_query_queue
Expand Down Expand Up @@ -760,6 +773,13 @@ public void executeByLegacy(TUniqueId queryId) throws Exception {
LOG.debug("no need to transfer to Master. stmt: {}", context.getStmtId());
}
} else {
// Query following createting table would throw table not exist error.
// For example.
// t1: client issues create table to master fe
// t2: client issues query sql to observer fe, the query would fail due to not exist table
// in plan phase.
// t3: observer fe receive editlog creating the table from the master fe
syncJournalIfNeeded();
analyzer = new Analyzer(context.getEnv(), context);
parsedStmt.analyze(analyzer);
parsedStmt.checkPriv();
Expand Down Expand Up @@ -947,7 +967,7 @@ public void updateProfile(boolean isFinished) {
}

// Analyze one statement to structure in memory.
public void analyze(TQueryOptions tQueryOptions) throws UserException, InterruptedException {
public void analyze(TQueryOptions tQueryOptions) throws UserException, InterruptedException, Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("begin to analyze stmt: {}, forwarded stmt id: {}", context.getStmtId(),
context.getForwardedStmtId());
Expand Down Expand Up @@ -988,6 +1008,13 @@ public void analyze(TQueryOptions tQueryOptions) throws UserException, Interrupt
return;
}

// Query following createting table would throw table not exist error.
// For example.
// t1: client issues create table to master fe
// t2: client issues query sql to observer fe, the query would fail due to not exist table in
// plan phase.
// t3: observer fe receive editlog creating the table from the master fe
syncJournalIfNeeded();
analyzer = new Analyzer(context.getEnv(), context);

if (parsedStmt instanceof PrepareStmt || context.getCommand() == MysqlCommand.COM_STMT_PREPARE) {
Expand Down

0 comments on commit 95484da

Please sign in to comment.