Skip to content

Commit 6d52fe3

Browse files
RMTTzhangyue-hashdata
authored andcommitted
Fix no response when alter io_limit of resource group to '-1' (#17095)
Fix no response when alter io_limit of resource group to '-1'. There is no action when ALTER RESOURCE GROUP xxx SET IO_LIMIT '-1' before. Now the action is that clear the content of io.max and update relation pg_resgroupcapability.
1 parent 0091dfa commit 6d52fe3

File tree

6 files changed

+67
-6
lines changed

6 files changed

+67
-6
lines changed

src/backend/commands/resgroupcmds.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,6 @@ AlterResourceGroup(AlterResourceGroupStmt *stmt)
486486

487487
validateCapabilities(pg_resgroupcapability_rel, groupid, &caps, false);
488488
AssertImply(limitType != RESGROUP_LIMIT_TYPE_IO_LIMIT, caps.io_limit == NIL);
489-
AssertImply(limitType == RESGROUP_LIMIT_TYPE_IO_LIMIT, caps.io_limit != NIL);
490489

491490
/* cpuset & cpu_max_percent can not coexist.
492491
* if cpuset is active, then cpu_max_percent must set to CPU_RATE_LIMIT_DISABLED,
@@ -519,6 +518,16 @@ AlterResourceGroup(AlterResourceGroupStmt *stmt)
519518
updateResgroupCapabilityEntry(pg_resgroupcapability_rel,
520519
groupid, RESGROUP_LIMIT_TYPE_IO_LIMIT,
521520
0, cgroupOpsRoutine->dumpio(caps.io_limit));
521+
else
522+
{
523+
/*
524+
* When alter io_limit to -1 , the caps.io_limit will be nil.
525+
* So we should update the io_limit in capability relation to -1.
526+
*/
527+
updateResgroupCapabilityEntry(pg_resgroupcapability_rel,
528+
groupid, RESGROUP_LIMIT_TYPE_IO_LIMIT,
529+
0, DefaultIOLimit);
530+
}
522531
}
523532
else
524533
{

src/backend/utils/resgroup/resgroup.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -807,11 +807,13 @@ ResGroupAlterOnCommit(const ResourceGroupCallbackContext *callbackCtx)
807807
}
808808
else if (callbackCtx->limittype == RESGROUP_LIMIT_TYPE_IO_LIMIT)
809809
{
810-
if (callbackCtx->caps.io_limit != NIL)
811-
{
812-
cgroupOpsRoutine->cleario(callbackCtx->groupid);
813-
cgroupOpsRoutine->setio(callbackCtx->groupid, callbackCtx->caps.io_limit);
814-
}
810+
/*
811+
* When alter io_limit to -1 , the caps.io_limit will be nil.
812+
* There are no errors in io_limit string when caps.io_limit is nil.
813+
* When alter io_limit, caps.io_limit is nil means this resource group's io_limit should be clear.
814+
*/
815+
cgroupOpsRoutine->cleario(callbackCtx->groupid);
816+
cgroupOpsRoutine->setio(callbackCtx->groupid, callbackCtx->caps.io_limit);
815817
}
816818

817819
/* reset default group if cpuset has changed */

src/test/isolation2/expected/resgroup/resgroup_auxiliary_tools_v2.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,9 @@ clear_io_max(groupid)
157157
cgroup_path = "/sys/fs/cgroup/gpdb/%d/io.max" % groupid
158158
return os.stat(cgroup_path).st_size == 0 $$ LANGUAGE plpython3u;
159159
CREATE
160+
161+
0: CREATE OR REPLACE FUNCTION check_io_max_empty(groupname text) RETURNS BOOL AS $$ import os
162+
# get group oid sql = "select groupid from gp_toolkit.gp_resgroup_config where groupname = '%s'" % groupname result = plpy.execute(sql) groupid = result[0]['groupid']
163+
cgroup_path = "/sys/fs/cgroup/gpdb/%d/io.max" % groupid
164+
return os.stat(cgroup_path).st_size == 0 $$ LANGUAGE plpython3u;
165+
CREATE

src/test/isolation2/input/resgroup/resgroup_io_limit.source

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ SELECT groupid, groupname, cpuset FROM gp_toolkit.gp_resgroup_config WHERE group
6969

7070
SELECT gp_inject_fault('create_resource_group_fail', 'reset', 1);
7171

72+
-- clear limitations
73+
CREATE RESOURCE GROUP rg_test_group7 WITH (concurrency=10, cpu_max_percent=10, io_limit='rg_io_limit_ts_1:rbps=1000,wbps=1000');
74+
75+
SELECT check_cgroup_io_max('rg_test_group7', 'rg_io_limit_ts_1', 'rbps=1048576000 wbps=1048576000 riops=max wiops=max');
76+
77+
ALTER RESOURCE GROUP rg_test_group7 SET IO_LIMIT '-1';
78+
79+
SELECT check_io_max_empty('rg_test_group7');
80+
7281
-- view
7382
-- start_ignore
7483
SELECT * from gp_toolkit.gp_resgroup_iostats_per_host;
@@ -82,6 +91,7 @@ DROP RESOURCE GROUP rg_test_group2;
8291
DROP RESOURCE GROUP rg_test_group3;
8392
DROP RESOURCE GROUP rg_test_group4;
8493
DROP RESOURCE GROUP rg_test_group5;
94+
DROP RESOURCE GROUP rg_test_group7;
8595

8696
DROP TABLESPACE rg_io_limit_ts_1;
8797

src/test/isolation2/output/resgroup/resgroup_io_limit.source

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,25 @@ SELECT gp_inject_fault('create_resource_group_fail', 'reset', 1);
137137
Success:
138138
(1 row)
139139

140+
-- clear limitations
141+
CREATE RESOURCE GROUP rg_test_group7 WITH (concurrency=10, cpu_max_percent=10, io_limit='rg_io_limit_ts_1:rbps=1000,wbps=1000');
142+
CREATE
143+
144+
SELECT check_cgroup_io_max('rg_test_group7', 'rg_io_limit_ts_1', 'rbps=1048576000 wbps=1048576000 riops=max wiops=max');
145+
check_cgroup_io_max
146+
---------------------
147+
t
148+
(1 row)
149+
150+
ALTER RESOURCE GROUP rg_test_group7 SET IO_LIMIT '-1';
151+
ALTER
152+
153+
SELECT check_io_max_empty('rg_test_group7');
154+
check_io_max_empty
155+
--------------------
156+
t
157+
(1 row)
158+
140159
-- view
141160
-- start_ignore
142161
SELECT * from gp_toolkit.gp_resgroup_iostats_per_host;
@@ -167,6 +186,8 @@ DROP RESOURCE GROUP rg_test_group4;
167186
DROP
168187
DROP RESOURCE GROUP rg_test_group5;
169188
DROP
189+
DROP RESOURCE GROUP rg_test_group7;
190+
DROP
170191

171192
DROP TABLESPACE rg_io_limit_ts_1;
172193
DROP

src/test/isolation2/sql/resgroup/resgroup_auxiliary_tools_v2.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,16 @@ $$ LANGUAGE plpython3u;
373373

374374
return os.stat(cgroup_path).st_size == 0
375375
$$ LANGUAGE plpython3u;
376+
377+
0: CREATE OR REPLACE FUNCTION check_io_max_empty(groupname text) RETURNS BOOL AS $$
378+
import os
379+
380+
# get group oid
381+
sql = "select groupid from gp_toolkit.gp_resgroup_config where groupname = '%s'" % groupname
382+
result = plpy.execute(sql)
383+
groupid = result[0]['groupid']
384+
385+
cgroup_path = "/sys/fs/cgroup/gpdb/%d/io.max" % groupid
386+
387+
return os.stat(cgroup_path).st_size == 0
388+
$$ LANGUAGE plpython3u;

0 commit comments

Comments
 (0)