Skip to content

Commit

Permalink
[Enhancement] improve error message of killed sql (#53708)
Browse files Browse the repository at this point in the history
Signed-off-by: Murphy <[email protected]>
  • Loading branch information
murphyatwork authored Dec 9, 2024
1 parent 880022b commit 2d7f483
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
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) + "...";
}
}
7 changes: 4 additions & 3 deletions fe/fe-core/src/main/java/com/starrocks/qe/ConnectContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.starrocks.common.DdlException;
import com.starrocks.common.ErrorCode;
import com.starrocks.common.ErrorReport;
import com.starrocks.common.util.SqlUtils;
import com.starrocks.common.util.TimeUtils;
import com.starrocks.common.util.UUIDUtil;
import com.starrocks.http.HttpConnectContext;
Expand Down Expand Up @@ -962,7 +963,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 @@ -1006,7 +1007,7 @@ public void checkTimeout(long now) {
if (delta > waitTimeout * 1000L) {
// Need kill this connection.
LOG.warn("kill wait timeout connection, remote: {}, wait timeout: {}, query id: {}, sql: {}",
getMysqlChannel().getRemoteHostPortString(), waitTimeout, queryId, sql);
getMysqlChannel().getRemoteHostPortString(), waitTimeout, queryId, SqlUtils.sqlPrefix(sql));

killFlag = true;
killConnection = true;
Expand All @@ -1018,7 +1019,7 @@ public void checkTimeout(long now) {
if (delta > timeoutSecond * 1000L) {
LOG.warn("kill timeout {}, remote: {}, execute timeout: {}, query id: {}, sql: {}",
getExecType().toLowerCase(), getMysqlChannel().getRemoteHostPortString(), timeoutSecond,
queryId, sql);
queryId, SqlUtils.sqlPrefix(sql));

// Only kill
killFlag = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,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 @@ -899,7 +899,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 @@ -954,7 +954,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

0 comments on commit 2d7f483

Please sign in to comment.