Skip to content

Commit 36b6ddd

Browse files
RMTTmy-ship-it
authored andcommitted
Add guc: gp_resource_group_cgroup_parent (#16738)
Add guc: gp_resource_group_cgroup_parent (only for cgroup v2). Current gpdb doesn't support change root cgroup path of resource group. For some situations, it's better if gpdb can change the root cgroup path of resource group. For example, on the OS with systemd, user maybe want to create a delegated cgroup to gpdb via systemd, but the delegated cgroup must end with .service which typically is /sys/fs/cgroup/gpdb.service. And in other OS without systemd, user maybe want to use /sys/fs/cgroup/gpdb or other locations directly. So add the gp_resource_group_cgroup_parent can make the resource group more flexible.
1 parent c4e0a80 commit 36b6ddd

9 files changed

Lines changed: 74 additions & 1 deletion

File tree

gpMgmt/bin/gpconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import os
1616
import sys
1717
import re
18+
import psutil
1819

1920
try:
2021
from gppylib.gpparseopts import OptParser, OptChecker
@@ -170,6 +171,20 @@ class Guc:
170171
return msg
171172
elif newval != "'queue'":
172173
return "the value of gp_resource_manager must be 'group' or 'group-v2' or 'queue'"
174+
elif self.name == "gp_resource_group_cgroup_parent":
175+
base = newval.strip("'")
176+
if not re.match("^[0-9a-zA-Z][-._0-9a-zA-Z]*$", base):
177+
return "resource group cgroup parent can only contains alphabet, number, and non-leading . _ -"
178+
179+
path = None
180+
for partition in psutil.disk_partitions(all=True):
181+
if partition.fstype == "cgroup2":
182+
path = partition.mountpoint + "/" + base
183+
break
184+
if path is None:
185+
return "cannot find cgroup v2 mountpoint"
186+
if not os.path.isdir(path):
187+
return "'%s' doesn't exists or is not a directory" % path
173188

174189
elif self.name == 'unix_socket_permissions':
175190
if newval[0] != '0':

src/backend/cdb/cdbvars.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
20+
#include "catalog/pg_collation_d.h"
2021
#include "postgres.h"
2122

2223
#include "miscadmin.h"
24+
#include "regex/regex.h"
2325
#include "utils/guc.h"
2426
#include "cdb/cdbvars.h"
2527
#include "libpq-fe.h"
@@ -567,6 +569,44 @@ gpvars_show_gp_resource_manager_policy(void)
567569
}
568570
}
569571

572+
bool gpvars_check_gp_resource_group_cgroup_parent(char **newval, void **extra, GucSource source)
573+
{
574+
int regres;
575+
char err[128];
576+
regex_t re;
577+
char *pattern = "^[0-9a-zA-Z][-._0-9a-zA-Z]*$";
578+
pg_wchar *wpattern = palloc((strlen(pattern) + 1) * sizeof(pg_wchar));
579+
int wlen = pg_mb2wchar_with_len(pattern, wpattern, strlen(pattern));
580+
pg_wchar *data = palloc((strlen(*newval) + 1) * sizeof(pg_wchar));
581+
int data_len = pg_mb2wchar_with_len(*newval, data, sizeof(*newval));
582+
bool match = true;
583+
584+
regres = pg_regcomp(&re, wpattern, wlen, REG_ADVANCED, DEFAULT_COLLATION_OID);
585+
if (regres != REG_OKAY)
586+
{
587+
pg_regerror(regres, &re, err, sizeof(err));
588+
GUC_check_errmsg("compile regex failed: %s", err);
589+
590+
pfree(wpattern);
591+
pfree(data);
592+
593+
return false;
594+
}
595+
596+
regres = pg_regexec(&re, data, data_len, 0, NULL, 0, NULL, 0);
597+
if (regres != REG_OKAY)
598+
{
599+
match = false;
600+
GUC_check_errmsg("gp_resource_group_cgroup_parent can only contains alphabet, number and non-leading . _ -");
601+
}
602+
603+
pg_regfree(&re);
604+
pfree(wpattern);
605+
pfree(data);
606+
607+
return match;
608+
}
609+
570610
/*
571611
* gpvars_assign_statement_mem
572612
*/

src/backend/utils/misc/guc_gp.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ double gp_resource_group_cpu_limit;
239239
bool gp_resource_group_bypass;
240240
bool gp_resource_group_bypass_catalog_query;
241241
bool gp_resource_group_bypass_direct_dispatch;
242+
char *gp_resource_group_cgroup_parent;
242243

243244
/* Metrics collector debug GUC */
244245
bool vmem_process_interrupt = false;
@@ -4900,6 +4901,17 @@ struct config_string ConfigureNamesString_gp[] =
49004901
gpvars_show_gp_resource_manager_policy,
49014902
},
49024903

4904+
{
4905+
{"gp_resource_group_cgroup_parent", PGC_POSTMASTER, RESOURCES,
4906+
gettext_noop("The root of gpdb cgroup hierarchy."),
4907+
NULL,
4908+
GUC_SUPERUSER_ONLY
4909+
},
4910+
&gp_resource_group_cgroup_parent,
4911+
"gpdb.service",
4912+
gpvars_check_gp_resource_group_cgroup_parent, NULL, NULL
4913+
},
4914+
49034915
/* for pljava */
49044916
{
49054917
{"pljava_vmoptions", PGC_SUSET, CUSTOM_OPTIONS,

src/backend/utils/resgroup/cgroup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ buildPathSafe(Oid group,
174174
* for cgroup v2, we just have the top level and child level,
175175
* don't need to care about the component.
176176
*/
177-
base_dir = base == BASEDIR_GPDB ? "gpdb" : "";
177+
base_dir = base == BASEDIR_GPDB ? gp_resource_group_cgroup_parent : "";
178178
len = snprintf(path, path_size, "%s/%s%s/%s",
179179
cgroupSystemInfo->cgroup_dir, base_dir, group_dir, filename);
180180
}

src/include/utils/guc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ extern void gpvars_assign_gp_resource_manager_policy(const char *newval, void *e
860860
extern const char *gpvars_show_gp_resource_manager_policy(void);
861861
extern const char *gpvars_assign_gp_resqueue_memory_policy(const char *newval, bool doit, GucSource source);
862862
extern const char *gpvars_show_gp_resqueue_memory_policy(void);
863+
extern bool gpvars_check_gp_resource_group_cgroup_parent(char **newval, void **extra, GucSource source);
863864
extern bool gpvars_check_statement_mem(int *newval, void **extra, GucSource source);
864865
extern bool gpvars_check_rg_query_fixed_mem(int *newval, void **extra, GucSource source);
865866
extern int guc_name_compare(const char *namea, const char *nameb);

src/include/utils/resgroup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ extern int gp_resource_group_queuing_timeout;
109109
extern bool gp_resource_group_bypass_catalog_query;
110110
extern int gp_resource_group_move_timeout;
111111
extern bool gp_resource_group_bypass_direct_dispatch;
112+
extern char *gp_resource_group_cgroup_parent;
112113

113114
/*
114115
* Non-GUC global variables.

src/include/utils/unsync_guc_name.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@
260260
"gp_resource_group_bypass_direct_dispatch",
261261
"gp_resource_group_queuing_timeout",
262262
"gp_resource_group_move_timeout",
263+
"gp_resource_group_cgroup_parent",
263264
"gp_resource_manager",
264265
"gp_resqueue_memory_policy",
265266
"gp_resqueue_priority",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ ERROR: language "plpython3u" already exists
2323
-- start_ignore
2424
! gpconfig -c gp_resource_manager -v group-v2;
2525

26+
! gpconfig -c gp_resource_group_cgroup_parent -v "gpdb"
27+
2628
! gpconfig -c max_connections -v 250 -m 25;
2729

2830
! gpconfig -c runaway_detector_activation_percent -v 100;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ CREATE LANGUAGE plpython3u;
2121
-- enable resource group and restart cluster.
2222
-- start_ignore
2323
! gpconfig -c gp_resource_manager -v group-v2;
24+
! gpconfig -c gp_resource_group_cgroup_parent -v "gpdb"
2425
! gpconfig -c max_connections -v 250 -m 25;
2526
! gpconfig -c runaway_detector_activation_percent -v 100;
2627
! gpstop -rai;

0 commit comments

Comments
 (0)