Skip to content

Commit

Permalink
[BugFix] Correct error message for query mem_limit exceeding parent (S…
Browse files Browse the repository at this point in the history
…tarRocks#35826)

Signed-off-by: zihe.liu <ziheliu1024@gmail.com>
  • Loading branch information
ZiheLiu authored Nov 28, 2023
1 parent 3f25332 commit c2d5d1d
Show file tree
Hide file tree
Showing 4 changed files with 382 additions and 15 deletions.
6 changes: 3 additions & 3 deletions be/src/exec/pipeline/query_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ int64_t QueryContext::compute_query_mem_limit(int64_t parent_mem_limit, int64_t
}
}

// query's mem_limit never exceeds its parent's limit if it exists
return parent_mem_limit == -1 ? mem_limit : std::min(parent_mem_limit, mem_limit);
return mem_limit;
}

void QueryContext::init_mem_tracker(int64_t query_mem_limit, MemTracker* parent, int64_t big_query_mem_limit,
Expand All @@ -130,7 +129,8 @@ void QueryContext::init_mem_tracker(int64_t query_mem_limit, MemTracker* parent,
auto* mem_tracker_counter =
ADD_COUNTER_SKIP_MERGE(_profile.get(), "MemoryLimit", TUnit::BYTES, TCounterMergeType::SKIP_ALL);
mem_tracker_counter->set(query_mem_limit);
if (wg != nullptr && big_query_mem_limit > 0 && big_query_mem_limit < query_mem_limit) {
if (wg != nullptr && big_query_mem_limit > 0 &&
(query_mem_limit <= 0 || big_query_mem_limit < query_mem_limit)) {
std::string label = "Group=" + wg->name() + ", " + _profile->name();
_mem_tracker = std::make_shared<MemTracker>(MemTracker::RESOURCE_GROUP_BIG_QUERY, big_query_mem_limit,
std::move(label), parent);
Expand Down
24 changes: 12 additions & 12 deletions be/test/exec/pipeline/query_context_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ TEST_P(ComputeQueryMemLimitTestFixture, compute_query_mem_limit) {
ASSERT_EQ(expected_result, result);
}

INSTANTIATE_TEST_SUITE_P(QueryContextTest, ComputeQueryMemLimitTestFixture,
::testing::Values(
// Not set per_instance_mem_limit and option_query_mem_limit.
std::make_tuple(100, -1, 4, -1, -1),
// Set option_query_mem_limit.
std::make_tuple(100, 2, 16, 4, 4), std::make_tuple(100, 2, 16, 101, 100),
// Set per_instance_mem_limit.
std::make_tuple(100, 2, 16, -1, 96), std::make_tuple(100, 4, 16, -1, 100),
// Set per_instance_mem_limit, and exceed MAX_INT64.
std::make_tuple(100, std::numeric_limits<int64_t>::max(), 16, -1, 100),
std::make_tuple(-1, std::numeric_limits<int64_t>::max(), 16, -1,
std::numeric_limits<int64_t>::max())));
INSTANTIATE_TEST_SUITE_P(
QueryContextTest, ComputeQueryMemLimitTestFixture,
::testing::Values(
// Not set per_instance_mem_limit and option_query_mem_limit.
std::make_tuple(100, -1, 4, -1, -1),
// Set option_query_mem_limit.
std::make_tuple(100, 2, 16, 4, 4), std::make_tuple(100, 2, 16, 101, 101),
// Set per_instance_mem_limit.
std::make_tuple(100, 2, 16, -1, 96), std::make_tuple(100, 4, 16, -1, 192),
// Set per_instance_mem_limit, and exceed MAX_INT64.
std::make_tuple(100, std::numeric_limits<int64_t>::max(), 16, -1, std::numeric_limits<int64_t>::max()),
std::make_tuple(-1, std::numeric_limits<int64_t>::max(), 16, -1, std::numeric_limits<int64_t>::max())));

} // namespace starrocks::pipeline
253 changes: 253 additions & 0 deletions test/sql/test_resource_group/R/test_resource_group_lt_query_mem_limit
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
-- name: test_resource_group_lt_query_mem_limit
create table t1 (
k1 int
)
duplicate key(k1)
distributed by hash(k1) buckets 32
properties("replication_num" = "1");
-- result:
-- !result
insert into t1 select generate_series FROM TABLE(generate_series(1, 65535));
-- result:
-- !result
insert into t1 select k1 + 65535 from t1;
-- result:
-- !result
insert into t1 select k1 + 65535*2 from t1;
-- result:
-- !result
insert into t1 select k1 + 65535*3 from t1;
-- result:
-- !result
create resource group rg_${uuid0}
to ( user='user_${uuid0}' )
with ('cpu_core_limit' = '1', 'mem_limit' = '0.0000000000001', 'concurrency_limit'='2');
-- result:
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.0000000000001','big_query_mem_limit'='0');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=0,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of the resource group.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.99','big_query_mem_limit'='0');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=0,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
524280
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.0000000000001','big_query_mem_limit'='1073741824000');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=0,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of the resource group.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.99','big_query_mem_limit'='1073741824000');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=0,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
524280
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.0000000000001','big_query_mem_limit'='1020');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=0,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of the resource group.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.99','big_query_mem_limit'='1020');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=0,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the big query limit of the resource group.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.0000000000001','big_query_mem_limit'='1024');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=0,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of the resource group.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.99','big_query_mem_limit'='1024');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=0,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the big query limit of the resource group.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.0000000000001','big_query_mem_limit'='0');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1073741824000,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of the resource group.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.99','big_query_mem_limit'='0');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1073741824000,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
524280
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.0000000000001','big_query_mem_limit'='1073741824000');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1073741824000,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of the resource group.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.99','big_query_mem_limit'='1073741824000');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1073741824000,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
524280
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.0000000000001','big_query_mem_limit'='1020');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1073741824000,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of the resource group.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.99','big_query_mem_limit'='1020');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1073741824000,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the big query limit of the resource group.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.0000000000001','big_query_mem_limit'='1024');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1073741824000,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of the resource group.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.99','big_query_mem_limit'='1024');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1073741824000,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the big query limit of the resource group.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.0000000000001','big_query_mem_limit'='0');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1020,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of single query.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.99','big_query_mem_limit'='0');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1020,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of single query.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.0000000000001','big_query_mem_limit'='1073741824000');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1020,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of single query.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.99','big_query_mem_limit'='1073741824000');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1020,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of single query.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.0000000000001','big_query_mem_limit'='1020');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1020,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of single query.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.99','big_query_mem_limit'='1020');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1020,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of single query.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.0000000000001','big_query_mem_limit'='1024');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1020,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of single query.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.99','big_query_mem_limit'='1024');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1020,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of single query.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.0000000000001','big_query_mem_limit'='0');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1024,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of single query.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.99','big_query_mem_limit'='0');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1024,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of single query.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.0000000000001','big_query_mem_limit'='1073741824000');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1024,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of single query.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.99','big_query_mem_limit'='1073741824000');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1024,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of single query.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.0000000000001','big_query_mem_limit'='1020');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1024,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of single query.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.99','big_query_mem_limit'='1020');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1024,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the big query limit of the resource group.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.0000000000001','big_query_mem_limit'='1024');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1024,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of single query.*
-- !result
alter resource group rg_${uuid0} with ('mem_limit'='0.99','big_query_mem_limit'='1024');
-- result:
-- !result
select /*+SET_VAR(query_mem_limit=1024,exec_mem_limit=0,resource_group='rg_${uuid0}')*/ count(1) from t1 where k1 > 0;
-- result:
[REGEX].*Mem usage has exceed the limit of single query.*
-- !result
drop resource group rg_${uuid0};
-- result:
-- !result
Loading

0 comments on commit c2d5d1d

Please sign in to comment.