Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.doris.nereids.exceptions;

/**
* Exception for can not fall back error in Nereids.
*/
public class DoNotFallbackException extends RuntimeException {
public DoNotFallbackException(String msg) {
super(msg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.doris.nereids.jobs.scheduler;

import org.apache.doris.nereids.CascadesContext;
import org.apache.doris.nereids.exceptions.DoNotFallbackException;
import org.apache.doris.nereids.jobs.Job;
import org.apache.doris.qe.SessionVariable;

Expand All @@ -36,7 +37,7 @@ public void executeJobPool(ScheduleContext scheduleContext) {
if (sessionVariable.enableNereidsTimeout
&& context.getStatementContext().getStopwatch().elapsed(TimeUnit.MILLISECONDS)
> sessionVariable.nereidsTimeoutSecond * 1000L) {
throw new RuntimeException(
throw new DoNotFallbackException(
"Nereids cost too much time ( > " + sessionVariable.nereidsTimeoutSecond + "s )");
}
Job job = pool.pop();
Expand Down
29 changes: 17 additions & 12 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 @@ -136,6 +136,7 @@
import org.apache.doris.nereids.NereidsPlanner;
import org.apache.doris.nereids.PlanProcess;
import org.apache.doris.nereids.StatementContext;
import org.apache.doris.nereids.exceptions.DoNotFallbackException;
import org.apache.doris.nereids.exceptions.MustFallbackException;
import org.apache.doris.nereids.exceptions.ParseException;
import org.apache.doris.nereids.glue.LogicalPlanAdapter;
Expand Down Expand Up @@ -520,7 +521,10 @@ public void execute() throws Exception {
execute(queryId);
}

public boolean notAllowFallback() {
public boolean notAllowFallback(NereidsException e) {
if (e.getException() instanceof DoNotFallbackException) {
return true;
}
if (parsedStmt instanceof LogicalPlanAdapter) {
LogicalPlan logicalPlan = ((LogicalPlanAdapter) parsedStmt).getLogicalPlan();
return logicalPlan instanceof NotAllowFallback;
Expand All @@ -545,12 +549,12 @@ public void execute(TUniqueId queryId) throws Exception {
}
// try to fall back to legacy planner
if (LOG.isDebugEnabled()) {
LOG.debug("nereids cannot process statement\n" + originStmt.originStmt
+ "\n because of " + e.getMessage(), e);
LOG.debug("nereids cannot process statement\n{}\n because of {}",
originStmt.originStmt, e.getMessage(), e);
}
if (notAllowFallback()) {
if (e instanceof NereidsException && notAllowFallback((NereidsException) e)) {
LOG.warn("Analyze failed. {}", context.getQueryIdentifier(), e);
throw ((NereidsException) e).getException();
throw new AnalysisException(e.getMessage());
}
// FIXME: Force fallback for:
// 1. group commit because nereids does not support it (see the following `isGroupCommit` variable)
Expand Down Expand Up @@ -705,7 +709,7 @@ private void executeByNereids(TUniqueId queryId) throws Exception {
syncJournalIfNeeded();
try {
((Command) logicalPlan).run(context, this);
} catch (MustFallbackException e) {
} catch (MustFallbackException | DoNotFallbackException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Command({}) process failed.", originStmt.originStmt, e);
}
Expand Down Expand Up @@ -751,10 +755,11 @@ private void executeByNereids(TUniqueId queryId) throws Exception {
try {
planner.plan(parsedStmt, context.getSessionVariable().toThrift());
checkBlockRules();
} catch (MustFallbackException | DoNotFallbackException e) {
LOG.warn("Nereids plan query failed:\n{}", originStmt.originStmt, e);
throw new NereidsException("Command(" + originStmt.originStmt + ") process failed.", e);
} catch (Exception e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Nereids plan query failed:\n{}", originStmt.originStmt);
}
LOG.warn("Nereids plan query failed:\n{}", originStmt.originStmt, e);
throw new NereidsException(new AnalysisException(e.getMessage(), e));
}
profile.getSummaryProfile().setQueryPlanFinishTime();
Expand Down Expand Up @@ -3286,10 +3291,10 @@ public HttpStreamParams generateHttpStreamPlan(TUniqueId queryId) throws Excepti
}
// try to fall back to legacy planner
if (LOG.isDebugEnabled()) {
LOG.debug("nereids cannot process statement\n" + originStmt.originStmt
+ "\n because of " + e.getMessage(), e);
LOG.debug("nereids cannot process statement\n{}\n because of {}",
originStmt.originStmt, e.getMessage(), e);
}
if (notAllowFallback()) {
if (e instanceof NereidsException && notAllowFallback((NereidsException) e)) {
LOG.warn("Analyze failed. {}", context.getQueryIdentifier(), e);
throw ((NereidsException) e).getException();
}
Expand Down
44 changes: 44 additions & 0 deletions regression-test/suites/nereids_p0/test_timeout_fallback.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

suite("test_timeout_fallback") {
sql "set enable_nereids_planner=true"
sql "set enable_fallback_to_original_planner=true"
sql "set enable_nereids_timeout=true"
sql "set nereids_timeout_second=-1"

test {
sql "select 1"
exception "Nereids cost too much time"
}

test {
sql "explain select 1"
exception "Nereids cost too much time"
}

sql "drop table if exists test_timeout_fallback"

sql """
create table test_timeout_fallback (id int) distributed by hash(id) properties ('replication_num'='1')
"""

test {
sql "insert into test_timeout_fallback values (1)"
exception "Nereids cost too much time"
}
}