JackieTien97 commented on code in PR #12155:
URL: https://github.com/apache/iotdb/pull/12155#discussion_r1522429472
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/Coordinator.java:
##########
@@ -235,19 +242,81 @@ public void cleanupQueryExecution(Long queryId, Throwable
t) {
queryExecutionMap.remove(queryId);
if (queryExecution.isQuery()) {
long costTime = queryExecution.getTotalExecutionTime();
- if (costTime / 1_000_000 >= CONFIG.getSlowQueryThreshold()) {
- SLOW_SQL_LOGGER.info(
- "Cost: {} ms, sql is {}",
- costTime / 1_000_000,
- queryExecution.getExecuteSQL().orElse("UNKNOWN"));
- }
+ outputSlowSql(queryExecution, costTime, nativeApiRequest);
}
}
}
}
+ private void outputSlowSql(
+ IQueryExecution queryExecution, long costTime, org.apache.thrift.TBase
request) {
+ if (costTime / 1_000_000 < CONFIG.getSlowQueryThreshold()) {
+ return;
+ }
+
+ String slowContent = "";
+ if (request == null ||
!queryExecution.getExecuteSQL().orElse("").isEmpty()) {
+ slowContent = String.format("sql is %s",
queryExecution.getExecuteSQL().orElse("UNKNOWN"));
+ } else if (request instanceof TSRawDataQueryReq) {
+ TSRawDataQueryReq req = (TSRawDataQueryReq) request;
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < Math.min(req.getPathsSize(),
MAX_SLOW_NATIVE_API_OUTPUT_NUM); i++) {
+ sb.append(i == 0 ? "" : ",").append(req.getPaths().get(i));
+ }
+ slowContent =
+ String.format(
+ "Request name: TSRawDataQueryReq, paths size: %s, starTime: %s, "
+ + "endTime: %s, some paths: %s",
+ req.getPathsSize(), req.getStartTime(), req.getEndTime(), sb);
+ } else if (request instanceof TSLastDataQueryReq) {
+ TSLastDataQueryReq req = (TSLastDataQueryReq) request;
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < Math.min(req.getPathsSize(),
MAX_SLOW_NATIVE_API_OUTPUT_NUM); i++) {
+ sb.append(i == 0 ? "" : ",").append(req.getPaths().get(i));
+ }
+ slowContent =
+ String.format(
+ "Request name: TSLastDataQueryReq, paths size: %s, some paths:
%s",
+ req.getPathsSize(), sb);
+ } else if (request instanceof TSAggregationQueryReq) {
+ TSAggregationQueryReq req = (TSAggregationQueryReq) request;
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < Math.min(req.getPathsSize(),
MAX_SLOW_NATIVE_API_OUTPUT_NUM); i++) {
+ sb.append(i == 0 ? "" : ",")
+ .append(req.getAggregations().get(i))
+ .append(":")
+ .append(req.getPaths().get(i));
+ }
+ slowContent =
+ String.format(
+ "Request name: TSAggregationQueryReq, startTime: %s, endTime:
%s, paths size: %s, some paths: %s",
+ req.getStartTime(), req.getEndTime(), req.getPathsSize(), sb);
+ } else if (request instanceof TSFastLastDataQueryForOneDeviceReq) {
+ TSFastLastDataQueryForOneDeviceReq req =
(TSFastLastDataQueryForOneDeviceReq) request;
+ slowContent =
+ String.format(
+ "Request name: TSFastLastDataQueryForOneDeviceReq, db: %s,
deviceId: %s, sensorSize: %s, sensors: %s",
+ req.getDb(), req.getDeviceId(), req.getSensorsSize(),
req.getSensors());
+ } else if (request instanceof TSFetchResultsReq) {
+ TSFetchResultsReq req = (TSFetchResultsReq) request;
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0;
+ i < Math.min(queryExecution.getOutputValueColumnCount(),
MAX_SLOW_NATIVE_API_OUTPUT_NUM);
+ i++) {
+ sb.append(i == 0 ? "" : ",")
+ .append(queryExecution.getDatasetHeader().getRespColumns().get(i));
+ }
+ slowContent =
+ String.format(
Review Comment:
total size.
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/ClientRPCServiceImpl.java:
##########
@@ -1103,7 +1103,7 @@ public TSFetchResultsResp
fetchResultsV2(TSFetchResultsReq req) {
long executionTime = COORDINATOR.getTotalExecutionTime(req.queryId);
addQueryLatency(
StatementType.QUERY, executionTime > 0 ? executionTime :
currentOperationCost);
- COORDINATOR.cleanupQueryExecution(req.queryId, t);
+ COORDINATOR.cleanupQueryExecution(req.queryId, req, t);
Review Comment:
also consider the catch exception block
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]