Skip to content

Commit

Permalink
[fix](timeout) query timeout was not correctly set #33045
Browse files Browse the repository at this point in the history
  • Loading branch information
Mryange authored Mar 30, 2024
1 parent 9f25205 commit bec153b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
21 changes: 20 additions & 1 deletion fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.apache.doris.plsql.Exec;
import org.apache.doris.plsql.executor.PlSqlOperation;
import org.apache.doris.plugin.audit.AuditEvent.AuditEventBuilder;
import org.apache.doris.proto.Types;
import org.apache.doris.resource.Tag;
import org.apache.doris.service.arrowflight.results.FlightSqlChannel;
import org.apache.doris.statistics.ColumnStatistic;
Expand Down Expand Up @@ -885,6 +886,24 @@ public void kill(boolean killConnection) {
cancelQuery();
}

// kill operation with no protect by timeout.
private void killByTimeout(boolean killConnection) {
LOG.warn("kill query from {}, kill mysql connection: {} reason time out", getRemoteHostPortString(),
killConnection);

if (killConnection) {
isKilled = true;
// Close channel to break connection with client
closeChannel();
}
// Now, cancel running query.
// cancelQuery by time out
StmtExecutor executorRef = executor;
if (executorRef != null) {
executorRef.cancel(Types.PPlanFragmentCancelReason.TIMEOUT);
}
}

public void cancelQuery() {
StmtExecutor executorRef = executor;
if (executorRef != null) {
Expand Down Expand Up @@ -925,7 +944,7 @@ public void checkTimeout(long now) {
}

if (killFlag) {
kill(killConnection);
killByTimeout(killConnection);
}
}

Expand Down
5 changes: 3 additions & 2 deletions fe/fe-core/src/main/java/org/apache/doris/qe/Coordinator.java
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ public RowBatch getNext() throws Exception {
resultBatch = receiver.getNext(status);
if (!status.ok()) {
LOG.warn("Query {} coordinator get next fail, {}, need cancel.",
DebugUtil.printId(queryId), status.toString());
DebugUtil.printId(queryId), status.getErrorMsg());
}

updateStatus(status);
Expand Down Expand Up @@ -1440,7 +1440,8 @@ public void cancel(Types.PPlanFragmentCancelReason cancelReason) {
} else {
queryStatus.setStatus(Status.CANCELLED);
}
LOG.warn("Cancel execution of query {}, this is a outside invoke", DebugUtil.printId(queryId));
LOG.warn("Cancel execution of query {}, this is a outside invoke, cancelReason {}",
DebugUtil.printId(queryId), cancelReason.toString());
cancelInternal(cancelReason);
} finally {
unlock();
Expand Down
14 changes: 14 additions & 0 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 @@ -1335,6 +1335,20 @@ public void cancel() {
}
}

// Because this is called by other thread
public void cancel(Types.PPlanFragmentCancelReason cancelReason) {
Coordinator coordRef = coord;
if (coordRef != null) {
coordRef.cancel(cancelReason);
}
if (mysqlLoadId != null) {
Env.getCurrentEnv().getLoadManager().getMysqlLoadManager().cancelMySqlLoad(mysqlLoadId);
}
if (parsedStmt instanceof AnalyzeTblStmt || parsedStmt instanceof AnalyzeDBStmt) {
Env.getCurrentEnv().getAnalysisManager().cancelSyncTask(context);
}
}

// Handle kill statement.
private void handleKill() throws DdlException {
KillStmt killStmt = (KillStmt) parsedStmt;
Expand Down

0 comments on commit bec153b

Please sign in to comment.