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
Query following createting table would throw table not exist error.

For example.
t1: client issue create table to master fe
t2: client issue 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

After the pr:
query at t2 would wait until latest edit log is received from master fe
in the observer fe.
  • Loading branch information
dataroaring committed Jul 11, 2024
1 parent 1eb04cf commit 2307723
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 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 @@ -693,6 +693,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 (MustFallbackException e) {
Expand Down Expand Up @@ -727,6 +734,13 @@ private void executeByNereids(TUniqueId queryId) throws Exception {
} else {
context.getState().setIsQuery(true);
// 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);
if (context.getSessionVariable().isEnableMaterializedViewRewrite()) {
planner.addHook(InitMaterializationContextHook.INSTANCE);
Expand Down Expand Up @@ -772,8 +786,6 @@ public void finalizeQuery() {

private void handleQueryWithRetry(TUniqueId queryId) throws Exception {
// queue query here
syncJournalIfNeeded();

int retryTime = Config.max_query_retry_time;
for (int i = 0; i < retryTime; i++) {
try {
Expand Down Expand Up @@ -863,6 +875,13 @@ public void executeByLegacy(TUniqueId queryId) throws Exception {
}
}
} 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 @@ -1113,6 +1132,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 2307723

Please sign in to comment.