This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.0 by this push:
new d1d30451adb branch-4.0: [fix](workload policy)query time based be
policy not work due to wrong finish_time_ #60456 (#60535)
d1d30451adb is described below
commit d1d30451adb44aecad51f6efe2938da42147ce87
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Fri Feb 6 11:27:28 2026 +0800
branch-4.0: [fix](workload policy)query time based be policy not work due
to wrong finish_time_ #60456 (#60535)
Cherry-picked from #60456
Co-authored-by: Wen Zhenghu <[email protected]>
---
.../runtime/workload_management/task_controller.h | 11 +++++-
be/test/runtime/workload_sched_policy_test.cpp | 41 ++++++++++++++++++++++
2 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/be/src/runtime/workload_management/task_controller.h
b/be/src/runtime/workload_management/task_controller.h
index c1d9fad4587..cd660cf2b46 100644
--- a/be/src/runtime/workload_management/task_controller.h
+++ b/be/src/runtime/workload_management/task_controller.h
@@ -64,7 +64,16 @@ public:
virtual void finish_impl() {}
int64_t start_time() const { return start_time_; }
int64_t finish_time() const { return finish_time_; }
- int64_t running_time() const { return finish_time() - start_time(); }
+ int64_t running_time() const {
+ if (start_time() == 0) {
+ return 0;
+ }
+ if (is_finished_) {
+ return finish_time() - start_time();
+ } else {
+ return MonotonicMillis() - start_time();
+ }
+ }
/* cancel action
*/
diff --git a/be/test/runtime/workload_sched_policy_test.cpp
b/be/test/runtime/workload_sched_policy_test.cpp
index e7cfea03695..df22a96b40e 100644
--- a/be/test/runtime/workload_sched_policy_test.cpp
+++ b/be/test/runtime/workload_sched_policy_test.cpp
@@ -101,6 +101,10 @@ TEST_F(WorkloadSchedPolicyTest, one_policy_one_condition) {
std::move(action_ptr_list));
WorkloadAction::RuntimeContext action_runtime_ctx =
create_runtime_context();
+ TUniqueId task_id;
+ task_id.hi = 1;
+ task_id.lo = 1;
+
action_runtime_ctx.resource_ctx->task_controller()->set_task_id(task_id);
std::this_thread::sleep_for(std::chrono::milliseconds(50));
action_runtime_ctx.resource_ctx->task_controller()->finish();
EXPECT_TRUE(policy->is_match(&action_runtime_ctx))
@@ -208,6 +212,10 @@ TEST_F(WorkloadSchedPolicyTest, one_policy_mutl_condition)
{
// 2. is match
WorkloadAction::RuntimeContext action_runtime_ctx =
create_runtime_context();
+ TUniqueId task_id;
+ task_id.hi = 1;
+ task_id.lo = 1;
+ action_runtime_ctx.resource_ctx->task_controller()->set_task_id(task_id);
std::shared_ptr<MemTrackerLimiter> mem_tracker =
MemTrackerLimiter::create_shared(MemTrackerLimiter::Type::QUERY,
"Test");
action_runtime_ctx.resource_ctx->memory_context()->set_mem_tracker(mem_tracker);
@@ -283,4 +291,37 @@ TEST_F(WorkloadSchedPolicyTest, test_wg_id_set) {
action_runtime_ctx.resource_ctx->set_workload_group(workload_group);
EXPECT_TRUE(policy->is_match(&action_runtime_ctx));
}
+
+TEST_F(WorkloadSchedPolicyTest, test_task_controller_running_time) {
+ std::shared_ptr<TaskController> task_controller =
std::make_shared<TaskController>();
+ TUniqueId task_id;
+ task_id.hi = 1;
+ task_id.lo = 1;
+
+ // 1. Before set_task_id, start_time is 0
+ EXPECT_EQ(task_controller->start_time(), 0);
+
+ // 2. set_task_id will init start_time
+ task_controller->set_task_id(task_id);
+ EXPECT_GT(task_controller->start_time(), 0);
+
+ // 3. running_time should be positive when running
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
+ int64_t running_time = task_controller->running_time();
+ EXPECT_GT(running_time, 0);
+ EXPECT_GE(running_time, 10);
+
+ // 4. finish task
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
+ task_controller->finish();
+ EXPECT_TRUE(task_controller->is_finished());
+
+ // 5. running_time should be fixed after finish
+ int64_t finished_running_time = task_controller->running_time();
+ EXPECT_GT(finished_running_time, running_time);
+
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
+ EXPECT_EQ(task_controller->running_time(), finished_running_time);
+}
+
} // namespace doris
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]