[feature](expr) Support kill query by query_id (#28530)

Issue Number: open #28517
This commit is contained in:
nanfeng
2023-12-19 18:18:40 +08:00
committed by GitHub
parent 71b7dcfb8f
commit 15e31d74e3
7 changed files with 60 additions and 5 deletions

View File

@ -25,10 +25,18 @@ package org.apache.doris.analysis;
public class KillStmt extends StatementBase {
private final boolean isConnectionKill;
private final int connectionId;
private final String queryId;
public KillStmt(boolean isConnectionKill, int connectionId) {
this.isConnectionKill = isConnectionKill;
this.connectionId = connectionId;
this.queryId = "";
}
public KillStmt(String queryId) {
this.isConnectionKill = false;
this.connectionId = -1;
this.queryId = queryId;
}
public boolean isConnectionKill() {
@ -39,6 +47,10 @@ public class KillStmt extends StatementBase {
return connectionId;
}
public String getQueryId() {
return queryId;
}
@Override
public void analyze(Analyzer analyzer) {
// No operation.

View File

@ -43,6 +43,7 @@ public enum ErrorCode {
ERR_NO_SUCH_THREAD(1094, new byte[]{'H', 'Y', '0', '0', '0'}, "Unknown thread id: %d"),
ERR_KILL_DENIED_ERROR(1095, new byte[]{'H', 'Y', '0', '0', '0'}, "You are not owner of thread %d"),
ERR_NO_TABLES_USED(1096, new byte[]{'H', 'Y', '0', '0', '0'}, "No tables used"),
ERR_NO_SUCH_QUERY(1097, new byte[]{'H', 'Y', '0', '0', '0'}, "Unknown query id: %s"),
ERR_WRONG_DB_NAME(1102, new byte[]{'4', '2', '0', '0', '0'}, "Incorrect database name '%s'"),
ERR_WRONG_TABLE_NAME(1103, new byte[]{'4', '2', '0', '0', '0'}, "Incorrect table name '%s'. Table name regex is '%s'"),
ERR_TOO_BIG_SELECT(1104, new byte[]{'4', '2', '0', '0', '0'}, "The SELECT would examine more than MAX_JOIN_SIZE "

View File

@ -126,6 +126,15 @@ public class ConnectScheduler {
return connectionMap.get(connectionId);
}
public ConnectContext getContextWithQueryId(String queryId) {
for (ConnectContext context : connectionMap.values()) {
if (queryId.equals(DebugUtil.printId(context.queryId))) {
return context;
}
}
return null;
}
public ConnectContext getContext(String flightToken) {
if (flightToken2ConnectionId.containsKey(flightToken)) {
int connectionId = flightToken2ConnectionId.get(flightToken);

View File

@ -1242,11 +1242,21 @@ public class StmtExecutor {
// Handle kill statement.
private void handleKill() throws DdlException {
KillStmt killStmt = (KillStmt) parsedStmt;
ConnectContext killCtx = null;
int id = killStmt.getConnectionId();
ConnectContext killCtx = context.getConnectScheduler().getContext(id);
if (killCtx == null) {
ErrorReport.reportDdlException(ErrorCode.ERR_NO_SUCH_THREAD, id);
String queryId = killStmt.getQueryId();
if (id == -1) {
killCtx = context.getConnectScheduler().getContextWithQueryId(queryId);
if (killCtx == null) {
ErrorReport.reportDdlException(ErrorCode.ERR_NO_SUCH_QUERY, queryId);
}
} else {
killCtx = context.getConnectScheduler().getContext(id);
if (killCtx == null) {
ErrorReport.reportDdlException(ErrorCode.ERR_NO_SUCH_THREAD, id);
}
}
if (context == killCtx) {
// Suicide
context.setKilled();