未验证 提交 68a0d35d 编写于 作者: X xiong-gang 提交者: GitHub

Minor fix in resource gorup move query

上级 c734e041
......@@ -498,6 +498,11 @@ pg_resgroup_move_query(PG_FUNCTION_ARGS)
Oid groupId;
const char *groupName;
if (!IsResGroupEnabled())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
(errmsg("resource group is not enabled"))));
if (!superuser())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
......
......@@ -26,7 +26,9 @@ $$ LANGUAGE sql;
-- @param pid: the pid of QD
-- @param groupname: resource group id
-- @return bool: true/false indicating whether it the session is in the resource group
-- start_ignore
CREATE LANGUAGE plpythonu;
-- end_ignore
CREATE OR REPLACE FUNCTION is_session_in_group(pid integer, groupname text) RETURNS BOOL AS $$
import subprocess
......@@ -49,7 +51,7 @@ process = subprocess.Popen("ps -ef | grep postgres | grep con%d | grep -v grep |
session_pids = process.communicate()[0].split('\n')[:-1]
cgroups_pids = []
path = "/sys/fs/cgroup/cpu/gpdb/%d/cgroup.procs" % groupid
path = "@cgroup_mnt_point@/cpu/gpdb/%d/cgroup.procs" % groupid
fd = open(path)
for line in fd.readlines():
cgroups_pids.append(line.strip('\n'))
......
......@@ -23,15 +23,17 @@ CREATE
-- @param pid: the pid of QD
-- @param groupname: resource group id
-- @return bool: true/false indicating whether it the session is in the resource group
-- start_ignore
CREATE LANGUAGE plpythonu;
CREATE
-- end_ignore
CREATE OR REPLACE FUNCTION is_session_in_group(pid integer, groupname text) RETURNS BOOL AS $$ import subprocess import pygresql.pg as pg import time import re
conn = pg.connect(dbname="isolation2resgrouptest") pt = re.compile(r'con(\d+)')
sql = "select sess_id from pg_stat_activity where pid = '%d'" % pid result = conn.query(sql).getresult() session_id = result[0][0]
sql = "select groupid from gp_toolkit.gp_resgroup_config where groupname='%s'" % groupname result = conn.query(sql).getresult() groupid = result[0][0]
process = subprocess.Popen("ps -ef | grep postgres | grep con%d | grep -v grep | awk '{print $2}'" % session_id, shell=True, stdout=subprocess.PIPE) session_pids = process.communicate()[0].split('\n')[:-1]
cgroups_pids = [] path = "/sys/fs/cgroup/cpu/gpdb/%d/cgroup.procs" % groupid fd = open(path) for line in fd.readlines(): cgroups_pids.append(line.strip('\n'))
cgroups_pids = [] path = "@cgroup_mnt_point@/cpu/gpdb/%d/cgroup.procs" % groupid fd = open(path) for line in fd.readlines(): cgroups_pids.append(line.strip('\n'))
return set(session_pids).issubset(set(cgroups_pids)) $$ LANGUAGE plpythonu;
CREATE
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册