github-actions[bot] commented on code in PR #65695:
URL: https://github.com/apache/doris/pull/65695#discussion_r3684391014


##########
be/test/runtime/workload_group/workload_group_manager_test.cpp:
##########
@@ -101,10 +102,12 @@ class WorkloadGroupManagerTest : public testing::Test {
 
 private:
     std::shared_ptr<QueryContext> 
_generate_on_query(std::shared_ptr<WorkloadGroup>& wg,
-                                                     int64_t mem_limit = 1024L 
* 1024 * 128) {
+                                                     int64_t mem_limit = 1024L 
* 1024 * 128,
+                                                     bool has_mem_limit = 
false) {
         TQueryOptions query_options;
         query_options.query_type = TQueryType::SELECT;
         query_options.mem_limit = mem_limit;
+        query_options.__isset.mem_limit = has_mem_limit;

Review Comment:
   [P1] Mark the explicit test limits as present
   
   With the default `has_mem_limit=false`, both new NONE and DYNAMIC 
restoration tests call this helper with `__isset.mem_limit` cleared. 
`_init_query_mem_tracker()` therefore stores the omitted-limit sentinel (`1 << 
60`), but those tests assert that `user_set_mem_limit()` is 128 MiB, so they 
fail before exercising restoration. Pass `true` in the cases intended to test 
an explicit 128 MiB cap, while keeping a separate absent-limit call for the 
sentinel path.



##########
be/test/runtime/workload_group/workload_group_manager_test.cpp:
##########
@@ -152,20 +155,70 @@ TEST_F(WorkloadGroupManagerTest, 
get_or_create_workload_group) {
     ASSERT_EQ(wg->id(), 0);
 }
 
+TEST_F(WorkloadGroupManagerTest, refresh_memory_usage_updates_memory_limits) {
+    const int64_t original_mem_limit = MemInfo::mem_limit();
+    Defer restore_mem_limit {[&]() { 
MemInfo::set_mem_limit_for_test(original_mem_limit); }};
+    const int64_t initial_mem_limit = 1024L * 1024 * 1024;
+    MemInfo::set_mem_limit_for_test(initial_mem_limit);
+
+    WorkloadGroupInfo wg_info {.id = 1,
+                               .memory_limit = initial_mem_limit / 2,
+                               .min_memory_percent = 25,
+                               .max_memory_percent = 50};
+    auto wg = _wg_manager->get_or_create_workload_group(wg_info);
+
+    EXPECT_EQ(wg->memory_limit(), initial_mem_limit / 2);
+    EXPECT_EQ(wg->min_memory_limit(), initial_mem_limit / 4);
+
+    const int64_t updated_mem_limit = initial_mem_limit * 2;
+    MemInfo::set_mem_limit_for_test(updated_mem_limit);
+    wg->refresh_memory_usage();
+
+    EXPECT_EQ(wg->memory_limit(), updated_mem_limit / 2);
+    EXPECT_EQ(wg->min_memory_limit(), updated_mem_limit / 4);
+}
+
 TEST_F(WorkloadGroupManagerTest, 
handle_paused_queries_ignores_empty_workload_group) {
     auto wg = _wg_manager->get_or_create_workload_group({});
 
     _wg_manager->handle_paused_queries();
 
     std::unique_lock<std::mutex> lock(_wg_manager->_paused_queries_lock);
-    ASSERT_FALSE(_wg_manager->_paused_queries_list.contains(wg));
+}
+
+TEST_F(WorkloadGroupManagerTest, 
refresh_restores_query_limit_after_cgroup_expands) {
+    const int64_t original_mem_limit = MemInfo::mem_limit();
+    Defer restore_mem_limit {[&]() { 
MemInfo::set_mem_limit_for_test(original_mem_limit); }};
+    const int64_t small_mem_limit = 1024L * 1024 * 20;
+    const int64_t large_mem_limit = 1024L * 1024 * 100;
+    MemInfo::set_mem_limit_for_test(small_mem_limit);
+    WorkloadGroupInfo wg_info {.id = 1,
+                               .memory_limit = small_mem_limit,
+                               .max_memory_percent = 100,
+                               .slot_mem_policy = TWgSlotMemoryPolicy::NONE};
+    auto wg = _wg_manager->get_or_create_workload_group(wg_info);
+    auto query_context = _generate_on_query(wg, large_mem_limit, true);
+    auto query_without_mem_limit = _generate_on_query(wg);
+
+    ASSERT_EQ(query_context->resource_ctx()->memory_context()->mem_limit(), 
small_mem_limit);
+    
ASSERT_EQ(query_context->resource_ctx()->memory_context()->user_set_mem_limit(),
+              large_mem_limit);
+    
ASSERT_EQ(query_without_mem_limit->resource_ctx()->memory_context()->mem_limit(),
+              small_mem_limit);
+
+    MemInfo::set_mem_limit_for_test(large_mem_limit);
+    _wg_manager->refresh_workload_group_memory_state();
+
+    ASSERT_EQ(wg->memory_limit(), large_mem_limit);
+    ASSERT_EQ(query_context->resource_ctx()->memory_context()->mem_limit(), 
large_mem_limit);
+    
ASSERT_EQ(query_without_mem_limit->resource_ctx()->memory_context()->mem_limit(),
+              large_mem_limit);
 }
 
 // Query is paused due to query memlimit exceed, after waiting in queue for  
spill_in_paused_queue_timeout_ms
 // it should be resumed
 TEST_F(WorkloadGroupManagerTest, query_exceed) {
     auto wg = _wg_manager->get_or_create_workload_group({});
-    auto query_context = _generate_on_query(wg);
 
     query_context->resource_ctx()->memory_context()->set_mem_limit(1024 * 
1024);

Review Comment:
   [P1] Restore the deleted test setup
   
   The only local declaration of `query_context` in this test was deleted, but 
lines 223-243 still dereference it and the fixture has no member by that name, 
so this BE-UT translation unit cannot compile. The same hunk also removes the 
only assertion from `handle_paused_queries_ignores_empty_workload_group`, 
leaving that test unable to check its named behavior. Please restore both the 
local `_generate_on_query(wg)` result and the preceding `ASSERT_FALSE`.



##########
be/src/runtime/query_context.cpp:
##########
@@ -157,33 +157,38 @@ QueryContext::QueryContext(TUniqueId query_id, ExecEnv* 
exec_env,
 }
 
 void QueryContext::_init_query_mem_tracker() {
+    // If user not set query limit, will use default 1TB memory limit. It is 
large enough to cover most cases.
+    constexpr int64_t DEFAULT_QUERY_MEM_LIMIT = 1LL << 60;
     bool has_query_mem_limit = _query_options.__isset.mem_limit && 
(_query_options.mem_limit > 0);
-    int64_t bytes_limit = has_query_mem_limit ? _query_options.mem_limit : -1;
-    if (bytes_limit > MemInfo::mem_limit() || bytes_limit == -1) {
-        VLOG_NOTICE << "Query memory limit " << 
PrettyPrinter::print(bytes_limit, TUnit::BYTES)
+    int64_t user_set_mem_limit =

Review Comment:
   [P1] Preserve the external caller's explicit cap
   
   `exec_external_plan_fragment()` assigns `query_options.mem_limit = 
params.mem_limit` without setting `TQueryOptions.__isset.mem_limit`, so this 
branch records the new `1 << 60` sentinel instead of the external cap. For 
example, a query opened with a 512 MiB cap while the process/group is 256 MiB 
starts at 256 MiB; after the cgroup expands to 1 GiB, NONE policy now computes 
`min(1 << 60, 1 GiB)` and raises the query tracker to 1 GiB. Before this 
change, `set_mem_tracker()` retained the initial 256 MiB limit, so the later 
refresh could not cross the caller's 512 MiB cap. Please preserve 
`params.__isset.mem_limit` when building `TQueryOptions` and cover an expansion 
that crosses the external cap.



-- 
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]

Reply via email to