yiguolei commented on code in PR #60567:
URL: https://github.com/apache/doris/pull/60567#discussion_r3176027746
##########
be/src/runtime/query_context.h:
##########
@@ -307,6 +314,14 @@ class QueryContext : public
std::enable_shared_from_this<QueryContext> {
Status reset_global_rf(const google::protobuf::RepeatedField<int32_t>&
filter_ids);
private:
+ // Task-level progress counters for current query.
+ std::atomic<int> _total_task_num {0};
+ std::atomic<int> _finished_task_num {0};
+
+ // Cached pointer to QueryTaskController, to avoid dynamic_cast on the hot
path
+ // (every inc_finished_task_num / add_total_task_num call).
+ class QueryTaskController* _query_task_controller = nullptr;
Review Comment:
不要保存这个,你看你保存的是裸指针。 这意味着,它可能在别的地方析构了,所以这里你继续访问就会core。
使用resource context,访问task controller
##########
be/src/runtime/query_context.cpp:
##########
@@ -543,4 +546,24 @@ Status QueryContext::reset_global_rf(const
google::protobuf::RepeatedField<int32
return Status::OK();
}
+void QueryContext::add_total_task_num(int delta) {
+ // Task total is accumulated once when fragment task graph is built.
+ _total_task_num.fetch_add(delta, std::memory_order_relaxed);
Review Comment:
total task num 和finished task num 已经在task controller 里保存了,就不要在query context
继续保存了。
你看我们的对象关系是: query context contains resource ctx, resource ctx 包含了 query
task controller。 所以你这么保存就冗余了。
##########
regression-test/suites/query_p0/test_query_progress.groovy:
##########
@@ -0,0 +1,117 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_query_progress") {
+ def tableName = "test_query_progress_tb"
+
+ // ---- setup: create table with some data ----
+ sql "DROP TABLE IF EXISTS ${tableName}"
+ sql """
+ CREATE TABLE IF NOT EXISTS ${tableName} (
+ k int,
+ v string
+ ) DUPLICATE KEY(`k`)
+ DISTRIBUTED BY HASH(`k`) BUCKETS 3
+ PROPERTIES ("replication_num" = "1");
+ """
+
+ // Insert enough data to make the subsequent query take measurable time.
+ // Using numbers() table function to generate rows.
+ sql """ INSERT INTO ${tableName}
+ SELECT number, repeat('x', 500)
+ FROM numbers("number" = "100000"); """
+
+ // ---- test 1: verify proc returns expected number of columns ----
+ // SHOW PROC '/current_queries' returns column layout:
+ // QueryId(0), ConnectionId(1), Catalog(2), Database(3), User(4),
+ // ExecTime(5), SqlHash(6), Statement(7),
+ // ScanRows(8), ScanBytes(9), ProcessRows(10), CpuMs(11),
+ // MaxPeakMemoryBytes(12), CurrentUsedMemoryBytes(13), WorkloadGroupId(14),
+ // ShuffleSendBytes(15), ShuffleSendRows(16),
+ // ScanBytesFromLocalStorage(17), ScanBytesFromRemoteStorage(18),
+ // SpillWriteBytesToLocalStorage(19), SpillReadBytesFromLocalStorage(20),
+ // BytesWriteIntoCache(21),
+ // TotalTasks(22), FinishedTasks(23), Progress(24)
+ // Total = 25 columns
+
+ // ---- test 2: verify progress values during a running query ----
+ // Run a query that takes long enough to observe progress.
+ def queryThread = new Thread({
+ sql """
+ SET parallel_pipeline_task_num = 6;
+ SELECT k, count(*), min(v), max(v)
+ FROM ${tableName}
+ GROUP BY k
+ ORDER BY k;
+ """
+ })
+ queryThread.setDaemon(true)
+ queryThread.start()
+
+ // Give the query a moment to start executing and register tasks
+ Thread.sleep(5000)
+
+ // Check progress while query is potentially still running
+ def progressResult = sql "SHOW PROC '/current_queries'"
+ logger.info("Current queries with progress: ${progressResult}")
+
+ // Validate that data rows have valid progress columns.
+ // Note: sql() returns List<List<String>> of data rows only — no header
row.
+ // Column indices: TotalTasks=22, FinishedTasks=23, Progress=24
+ if (!progressResult.isEmpty()) {
+ for (int i = 0; i < progressResult.size(); i++) {
+ def row = progressResult[i]
+ assertTrue(row.size() >= 25,
+ "Expected at least 25 columns (through Progress), got
${row.size()}")
Review Comment:
不要加这个case,这种case 一般不稳定
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]