Skip to content

Commit

Permalink
[Enhancement] print query_id when swallowing the exception (#50965)
Browse files Browse the repository at this point in the history
Signed-off-by: Murphy <[email protected]>
(cherry picked from commit 02137a3)
Signed-off-by: Murphy <[email protected]>

# Conflicts:
#	fe/fe-core/src/main/java/com/starrocks/sql/optimizer/Utils.java
  • Loading branch information
murphyatwork committed Sep 18, 2024
1 parent 0911fcb commit 3b3847a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/common/util/DebugUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.google.common.base.Joiner;
import com.starrocks.common.Pair;
import com.starrocks.proto.PUniqueId;
import com.starrocks.qe.ConnectContext;
import com.starrocks.thrift.TUniqueId;
import org.apache.commons.lang.exception.ExceptionUtils;

Expand Down Expand Up @@ -179,4 +180,15 @@ public static String getRootStackTrace(Throwable e) {
String[] stacks = ExceptionUtils.getRootCauseStackTrace(e);
return Joiner.on("\n").join(stacks);
}

/**
* Get the query-id for current session
*/
public static String getSessionQueryId() {
ConnectContext ctx = ConnectContext.get();
if (ctx == null || ctx.getQueryId() == null) {
return null;
}
return printId(ctx.getQueryId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.starrocks.catalog.Table;
import com.starrocks.catalog.Type;
import com.starrocks.common.Pair;
import com.starrocks.common.util.DebugUtil;
import com.starrocks.qe.ConnectContext;
import com.starrocks.server.GlobalStateMgr;
import com.starrocks.sql.optimizer.base.LogicalProperty;
Expand Down Expand Up @@ -784,7 +785,8 @@ public static void calculateStatistics(OptExpression expr, OptimizerContext cont
try {
statisticsCalculator.estimatorStats();
} catch (Exception e) {
LOG.warn("Failed to calculate statistics for expression: {}", expr, e);
LOG.warn("[query={}] Failed to calculate statistics for expression: {}",
DebugUtil.getSessionQueryId(), expr, e);
return;
}

Expand Down

0 comments on commit 3b3847a

Please sign in to comment.