Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] improve error message of killed sql (backport #53708) #53731

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 15 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/common/util/SqlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@

package com.starrocks.common.util;

import org.apache.commons.lang3.StringUtils;

public class SqlUtils {

private static final int SQL_PREFIX_LENGTH = 128;

public static String escapeUnquote(String ident) {
return ident.replaceAll("``", "`");
}
Expand All @@ -35,4 +40,14 @@ public static String getIdentSql(String ident) {
sb.append('`');
return sb.toString();
}

/**
* Return the prefix of a sql if it's too long
*/
public static String sqlPrefix(String sql) {
if (StringUtils.isEmpty(sql) || sql.length() < SQL_PREFIX_LENGTH) {
return sql;
}
return sql.substring(0, SQL_PREFIX_LENGTH) + "...";
}
}
18 changes: 17 additions & 1 deletion fe/fe-core/src/main/java/com/starrocks/qe/ConnectContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
import com.google.common.collect.Sets;
import com.starrocks.cluster.ClusterNamespace;
import com.starrocks.common.DdlException;
<<<<<<< HEAD
=======
import com.starrocks.common.ErrorCode;
import com.starrocks.common.ErrorReport;
import com.starrocks.common.util.SqlUtils;
>>>>>>> 2d7f4836d4 ([Enhancement] improve error message of killed sql (#53708))
import com.starrocks.common.util.TimeUtils;
import com.starrocks.http.HttpConnectContext;
import com.starrocks.mysql.MysqlCapability;
Expand Down Expand Up @@ -781,7 +787,7 @@ public void kill(boolean killConnection, String cancelledMessage) {
Thread.sleep(10);
times++;
if (times > 100) {
LOG.warn("wait for close fail, break.");
LOG.warn("kill queryId={} connectId={} wait for close fail, break.", queryId, connectionId);
break;
}
} catch (InterruptedException e) {
Expand Down Expand Up @@ -812,16 +818,26 @@ public void checkTimeout(long now) {
if (delta > sessionVariable.getWaitTimeoutS() * 1000L) {
// Need kill this connection.
LOG.warn("kill wait timeout connection, remote: {}, wait timeout: {}, query id: {}, sql: {}",
<<<<<<< HEAD
getMysqlChannel().getRemoteHostPortString(), sessionVariable.getWaitTimeoutS(), queryId, sql);
=======
getMysqlChannel().getRemoteHostPortString(), waitTimeout, queryId, SqlUtils.sqlPrefix(sql));
>>>>>>> 2d7f4836d4 ([Enhancement] improve error message of killed sql (#53708))

killFlag = true;
killConnection = true;
}
} else {
long timeoutSecond = sessionVariable.getQueryTimeoutS();
if (delta > timeoutSecond * 1000L) {
<<<<<<< HEAD
LOG.warn("kill query timeout, remote: {}, query timeout: {}, query id: {}, sql: {}",
getMysqlChannel().getRemoteHostPortString(), sessionVariable.getQueryTimeoutS(), queryId, sql);
=======
LOG.warn("kill timeout {}, remote: {}, execute timeout: {}, query id: {}, sql: {}",
getExecType().toLowerCase(), getMysqlChannel().getRemoteHostPortString(), timeoutSecond,
queryId, SqlUtils.sqlPrefix(sql));
>>>>>>> 2d7f4836d4 ([Enhancement] improve error message of killed sql (#53708))

// Only kill
killFlag = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void run() {
}
} catch (Throwable e) {
//Catch Exception to avoid thread exit
LOG.warn("Timeout checker exception, Internal error : " + e.getMessage());
LOG.warn("Timeout checker exception, Internal error : {}", e.getMessage(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ public RowBatch getNext() throws Exception {
throw new RpcException("unknown", copyStatus.getErrorMsg());
} else {
String errMsg = copyStatus.getErrorMsg();
LOG.warn("query failed: {}", errMsg);
LOG.warn("query {} failed: {}", connectContext.queryId, errMsg);

// hide host info
int hostIndex = errMsg.indexOf("host");
Expand Down Expand Up @@ -831,7 +831,7 @@ public void cancel(PPlanFragmentCancelReason reason, String message) {
queryStatus.setStatus(Status.CANCELLED);
queryStatus.setErrorMsg(message);
}
LOG.warn("cancel execState of query, this is outside invoke");
LOG.info("cancel query {} because {}", connectContext.queryId, message);
cancelInternal(reason);
} finally {
try {
Expand Down
Loading