[CP] adjust cgroup interface
This commit is contained in:
parent
a6e96d5c73
commit
e8a2f9f6e9
@ -2559,7 +2559,9 @@ void ObMultiTenant::run1()
|
||||
if (!OB_ISNULL(*it)) {
|
||||
ObTaskController::get().allow_next_syslog();
|
||||
LOG_INFO("dump tenant info", "tenant", **it);
|
||||
(*it)->print_throttled_time();
|
||||
if (OB_NOT_NULL(GCTX.cgroup_ctrl_) && GCTX.cgroup_ctrl_->is_valid()) {
|
||||
(*it)->print_throttled_time();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -607,12 +607,7 @@ int ObResourceGroup::get_throttled_time(int64_t &throttled_time)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t current_throttled_time_us = -1;
|
||||
if (OB_ISNULL(GCTX.cgroup_ctrl_) || !GCTX.cgroup_ctrl_->is_valid()) {
|
||||
// do nothing
|
||||
} else if (OB_FAIL(GCTX.cgroup_ctrl_->get_throttled_time(tenant_->id(),
|
||||
current_throttled_time_us,
|
||||
group_id_,
|
||||
GCONF.enable_global_background_resource_isolation ? BACKGROUND_CGROUP : ""))) {
|
||||
if (OB_FAIL(GCTX.cgroup_ctrl_->get_throttled_time(tenant_->id(), current_throttled_time_us, group_id_))) {
|
||||
LOG_WARN("get throttled time failed", K(ret), K(tenant_->id()), K(group_id_));
|
||||
} else if (current_throttled_time_us > 0) {
|
||||
throttled_time = current_throttled_time_us - throttled_time_us_;
|
||||
@ -1171,9 +1166,10 @@ void ObTenant::destroy()
|
||||
common::ob_delete(mtl_init_ctx_);
|
||||
mtl_init_ctx_ = nullptr;
|
||||
}
|
||||
if (cgroup_ctrl_.is_valid() &&
|
||||
OB_TMP_FAIL(cgroup_ctrl_.remove_both_cgroup(
|
||||
id_, OB_INVALID_GROUP_ID, GCONF.enable_global_background_resource_isolation ? BACKGROUND_CGROUP : ""))) {
|
||||
|
||||
if (!cgroup_ctrl_.is_valid()) {
|
||||
// do nothing
|
||||
} else if (OB_TMP_FAIL(cgroup_ctrl_.remove_cgroup(id_))) {
|
||||
LOG_WARN_RET(tmp_ret, "remove tenant cgroup failed", K(tmp_ret), K_(id));
|
||||
}
|
||||
}
|
||||
@ -1184,11 +1180,7 @@ void ObTenant::set_unit_max_cpu(double cpu)
|
||||
unit_max_cpu_ = cpu;
|
||||
if (!cgroup_ctrl_.is_valid() || is_meta_tenant(id_)) {
|
||||
// do nothing
|
||||
} else if (OB_TMP_FAIL(cgroup_ctrl_.set_both_cpu_cfs_quota(
|
||||
id_,
|
||||
is_sys_tenant(id_) ? -1 : cpu,
|
||||
OB_INVALID_GROUP_ID,
|
||||
GCONF.enable_global_background_resource_isolation ? BACKGROUND_CGROUP : ""))) {
|
||||
} else if (OB_TMP_FAIL(cgroup_ctrl_.set_cpu_cfs_quota(id_, is_sys_tenant(id_) ? -1 : cpu))) {
|
||||
LOG_WARN_RET(tmp_ret, "set tenant cpu cfs quota failed", K(tmp_ret), K_(id));
|
||||
}
|
||||
}
|
||||
@ -1197,12 +1189,9 @@ void ObTenant::set_unit_min_cpu(double cpu)
|
||||
{
|
||||
int tmp_ret = OB_SUCCESS;
|
||||
unit_min_cpu_ = cpu;
|
||||
if (cgroup_ctrl_.is_valid() &&
|
||||
OB_TMP_FAIL(cgroup_ctrl_.set_both_cpu_shares(
|
||||
id_,
|
||||
cpu,
|
||||
OB_INVALID_GROUP_ID,
|
||||
GCONF.enable_global_background_resource_isolation ? BACKGROUND_CGROUP : ""))) {
|
||||
if (!cgroup_ctrl_.is_valid()) {
|
||||
// do nothing
|
||||
} else if (OB_TMP_FAIL(cgroup_ctrl_.set_cpu_shares(id_, cpu))) {
|
||||
LOG_WARN_RET(tmp_ret, "set tenant cpu shares failed", K(tmp_ret), K_(id), K(cpu));
|
||||
}
|
||||
}
|
||||
|
@ -2399,12 +2399,7 @@ int ObTenantIOManager::get_throttled_time(uint64_t group_id, int64_t &throttled_
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t current_throttled_time_us = -1;
|
||||
if (OB_ISNULL(GCTX.cgroup_ctrl_) || !GCTX.cgroup_ctrl_->is_valid()) {
|
||||
// do nothing
|
||||
} else if (OB_FAIL(GCTX.cgroup_ctrl_->get_throttled_time(tenant_id_,
|
||||
current_throttled_time_us,
|
||||
group_id,
|
||||
GCONF.enable_global_background_resource_isolation ? BACKGROUND_CGROUP : ""))) {
|
||||
if (OB_FAIL(GCTX.cgroup_ctrl_->get_throttled_time(tenant_id_, current_throttled_time_us, group_id))) {
|
||||
LOG_WARN("get throttled time failed", K(ret), K(tenant_id_), K(group_id));
|
||||
} else if (current_throttled_time_us > 0) {
|
||||
uint64_t idx = 0;
|
||||
|
@ -46,8 +46,8 @@ int SET_GROUP_ID(uint64_t group_id, bool is_background)
|
||||
|
||||
THIS_WORKER.set_group_id_(group_id);
|
||||
int tmp_ret = OB_SUCCESS;
|
||||
if (OB_NOT_NULL(GCTX.cgroup_ctrl_)
|
||||
&& OB_TMP_FAIL(GCTX.cgroup_ctrl_->add_self_to_cgroup_(MTL_ID(), group_id, is_background))) {
|
||||
if (OB_NOT_NULL(GCTX.cgroup_ctrl_) &&
|
||||
OB_TMP_FAIL(GCTX.cgroup_ctrl_->add_self_to_cgroup_(MTL_ID(), group_id, is_background))) {
|
||||
LOG_WARN("add self to cgroup fail", K(ret), K(MTL_ID()), K(group_id));
|
||||
}
|
||||
return ret;
|
||||
@ -117,7 +117,7 @@ bool ObCgroupCtrl::is_valid_group_name(ObString &group_name)
|
||||
if (group_name.length() < 0 || group_name.length() > GROUP_NAME_BUFSIZE) {
|
||||
bool_ret = false;
|
||||
} else {
|
||||
for(int i = 0; i < group_name.length() && bool_ret; i++) {
|
||||
for (int i = 0; i < group_name.length() && bool_ret; i++) {
|
||||
// only support [a-zA-Z0-9_]
|
||||
if (!((group_name_ptr[i] >= 'a' && group_name_ptr[i] <= 'z') ||
|
||||
(group_name_ptr[i] >= 'A' && group_name_ptr[i] <= 'Z') ||
|
||||
@ -200,7 +200,7 @@ int ObCgroupCtrl::remove_dir_(const char *curr_dir, bool is_delete_group)
|
||||
} else {
|
||||
snprintf(target_task_path, PATH_BUFSIZE, "%s/../OBCG_DEFAULT/tasks", curr_dir);
|
||||
}
|
||||
FILE* group_task_file = nullptr;
|
||||
FILE *group_task_file = nullptr;
|
||||
if (OB_ISNULL(group_task_file = fopen(group_task_path, "r"))) {
|
||||
ret = OB_IO_ERROR;
|
||||
LOG_WARN("open group failed", K(ret), K(group_task_path), K(errno), KERRMSG);
|
||||
@ -224,17 +224,17 @@ int ObCgroupCtrl::remove_dir_(const char *curr_dir, bool is_delete_group)
|
||||
return ret;
|
||||
}
|
||||
|
||||
class RemoveProccessor : public ObCgroupCtrl::DirProcessor
|
||||
{
|
||||
public:
|
||||
int handle_dir(const char *curr_path, bool is_top_dir)
|
||||
{
|
||||
UNUSED(is_top_dir);
|
||||
return ObCgroupCtrl::remove_dir_(curr_path);
|
||||
}
|
||||
};
|
||||
int ObCgroupCtrl::recursion_remove_group_(const char *curr_path)
|
||||
{
|
||||
class RemoveProccessor : public ObCgroupCtrl::DirProcessor
|
||||
{
|
||||
public:
|
||||
int handle_dir(const char *curr_path, bool is_top_dir)
|
||||
{
|
||||
UNUSED(is_top_dir);
|
||||
return ObCgroupCtrl::remove_dir_(curr_path);
|
||||
}
|
||||
};
|
||||
RemoveProccessor remove_process;
|
||||
return recursion_process_group_(curr_path, &remove_process, true /* is_top_dir */);
|
||||
}
|
||||
@ -281,11 +281,11 @@ int ObCgroupCtrl::recursion_process_group_(const char *curr_path, DirProcessor *
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObCgroupCtrl::remove_cgroup(const uint64_t tenant_id, uint64_t group_id, const char *base_path)
|
||||
int ObCgroupCtrl::remove_cgroup_(const uint64_t tenant_id, uint64_t group_id, const bool is_background)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
char group_path[PATH_BUFSIZE];
|
||||
if (OB_FAIL(get_group_path(group_path, PATH_BUFSIZE, tenant_id, group_id, base_path))) {
|
||||
if (OB_FAIL(get_group_path(group_path, PATH_BUFSIZE, tenant_id, group_id, is_background))) {
|
||||
LOG_WARN("fail get group path", K(tenant_id), K(ret));
|
||||
} else if (is_valid_group(group_id)) {
|
||||
ret = remove_dir_(group_path, true /* is_delete_group */);
|
||||
@ -300,24 +300,25 @@ int ObCgroupCtrl::remove_cgroup(const uint64_t tenant_id, uint64_t group_id, con
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObCgroupCtrl::remove_both_cgroup(const uint64_t tenant_id, const uint64_t group_id, const char *base_path)
|
||||
int ObCgroupCtrl::remove_cgroup(const uint64_t tenant_id, const uint64_t group_id, const bool is_background)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(remove_cgroup(tenant_id, group_id))) {
|
||||
LOG_WARN("remove tenant cgroup directory failed", K(ret), K(tenant_id));
|
||||
} else if (OB_NOT_NULL(base_path) && 0 != STRLEN(base_path) && OB_FAIL(remove_cgroup(tenant_id, group_id, base_path))) {
|
||||
LOG_WARN("remove background tenant cgroup directory failed", K(ret), K(tenant_id));
|
||||
if (!(is_background && GCONF.enable_global_background_resource_isolation)) {
|
||||
if (OB_FAIL(remove_cgroup_(tenant_id, group_id, false /* is_background */))) {
|
||||
LOG_WARN("remove tenant cgroup directory failed", K(ret), K(tenant_id));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret) && GCONF.enable_global_background_resource_isolation) {
|
||||
if (OB_FAIL(remove_cgroup_(tenant_id, group_id, true /* is_background */))) {
|
||||
LOG_WARN("remove background tenant cgroup directory failed", K(ret), K(tenant_id));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// return "root_cgroup_path/[base_path]/[user_tenant_path]/[meta_tenant_path]/[group_path]"
|
||||
int ObCgroupCtrl::get_group_path(
|
||||
char *group_path,
|
||||
int path_bufsize,
|
||||
const uint64_t tenant_id,
|
||||
uint64_t group_id,
|
||||
const char *base_path)
|
||||
char *group_path, int path_bufsize, const uint64_t tenant_id, uint64_t group_id, const bool is_background)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
|
||||
@ -325,9 +326,11 @@ int ObCgroupCtrl::get_group_path(
|
||||
char user_tenant_path[PATH_BUFSIZE] = "";
|
||||
char meta_tenant_path[PATH_BUFSIZE] = "";
|
||||
char group_name_path[PATH_BUFSIZE] = "";
|
||||
// gen root_cgroup_path
|
||||
if (!is_valid_tenant_id(tenant_id)) {
|
||||
if (OB_NOT_NULL(base_path) && 0 != STRLEN(base_path)) {
|
||||
if (!is_valid()) {
|
||||
ret = OB_INVALID_CONFIG;
|
||||
} else if (!is_valid_tenant_id(tenant_id)) {
|
||||
// gen root_cgroup_path
|
||||
if (is_background) {
|
||||
// background base, return "cgroup/background"
|
||||
snprintf(root_cgroup_path, path_bufsize, "%s", root_cgroup_);
|
||||
} else {
|
||||
@ -340,10 +343,6 @@ int ObCgroupCtrl::get_group_path(
|
||||
} else {
|
||||
snprintf(root_cgroup_path, path_bufsize, "%s", root_cgroup_);
|
||||
|
||||
if (OB_ISNULL(base_path)) {
|
||||
base_path = "";
|
||||
}
|
||||
|
||||
// gen tenant_path
|
||||
if (!is_valid_tenant_id(tenant_id)) {
|
||||
// do nothing
|
||||
@ -367,7 +366,7 @@ int ObCgroupCtrl::get_group_path(
|
||||
const char *group_name = nullptr;
|
||||
share::ObGroupName g_name;
|
||||
int tmp_ret = OB_SUCCESS;
|
||||
const int64_t WARN_LOG_INTERVAL = 3600 * 1000 * 1000L; // 1 hour
|
||||
const int64_t WARN_LOG_INTERVAL = 3600 * 1000 * 1000L; // 1 hour
|
||||
ObCgSet &set = ObCgSet::instance();
|
||||
|
||||
if (is_resource_manager_group(group_id)) {
|
||||
@ -376,7 +375,7 @@ int ObCgroupCtrl::get_group_path(
|
||||
if (REACH_TIME_INTERVAL(WARN_LOG_INTERVAL)) {
|
||||
LOG_WARN("fail to get group_name", K(tmp_ret), K(tenant_id), K(group_id), K(lbt()));
|
||||
}
|
||||
ret = OB_SUCCESS; // ignore error
|
||||
ret = OB_SUCCESS; // ignore error
|
||||
} else {
|
||||
group_name = g_name.get_value().ptr();
|
||||
}
|
||||
@ -405,7 +404,7 @@ int ObCgroupCtrl::get_group_path(
|
||||
}
|
||||
|
||||
if (OB_SUCCESS == tmp_ret && is_resource_manager_group(group_id)) {
|
||||
snprintf(group_name_path, path_bufsize, "OBRM_%s", group_name); // resource manager
|
||||
snprintf(group_name_path, path_bufsize, "OBRM_%s", group_name); // resource manager
|
||||
} else {
|
||||
snprintf(group_name_path, path_bufsize, "%s", group_name);
|
||||
}
|
||||
@ -416,7 +415,7 @@ int ObCgroupCtrl::get_group_path(
|
||||
path_bufsize,
|
||||
"%s/%s/%s/%s/%s",
|
||||
root_cgroup_path,
|
||||
base_path,
|
||||
is_background ? "background" : "",
|
||||
user_tenant_path,
|
||||
meta_tenant_path,
|
||||
group_name_path);
|
||||
@ -428,16 +427,15 @@ int ObCgroupCtrl::add_self_to_cgroup_(const uint64_t tenant_id, const uint64_t g
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (is_valid()) {
|
||||
|
||||
const char *base_path =
|
||||
(GCONF.enable_global_background_resource_isolation && is_background) ? BACKGROUND_CGROUP : "";
|
||||
char group_path[PATH_BUFSIZE];
|
||||
char tid_value[VALUE_BUFSIZE + 1];
|
||||
|
||||
snprintf(tid_value, VALUE_BUFSIZE, "%ld", gettid());
|
||||
if (OB_FAIL(ret)) {
|
||||
// do nothing
|
||||
} else if (OB_FAIL(get_group_path(group_path, PATH_BUFSIZE, tenant_id, group_id, base_path))) {
|
||||
if (OB_FAIL(get_group_path(group_path,
|
||||
PATH_BUFSIZE,
|
||||
tenant_id,
|
||||
group_id,
|
||||
is_background && GCONF.enable_global_background_resource_isolation))) {
|
||||
LOG_WARN("fail get group path", K(tenant_id), K(ret));
|
||||
} else if (OB_FAIL(set_cgroup_config_(group_path, TASKS_FILE, tid_value))) {
|
||||
LOG_WARN("add tid to cgroup failed", K(ret), K(group_path), K(tid_value), K(tenant_id));
|
||||
@ -448,11 +446,9 @@ int ObCgroupCtrl::add_self_to_cgroup_(const uint64_t tenant_id, const uint64_t g
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// TODO: 查表,通过 group id 找到 group 名字
|
||||
int ObCgroupCtrl::get_group_info_by_group_id(const uint64_t tenant_id,
|
||||
uint64_t group_id,
|
||||
share::ObGroupName &group_name)
|
||||
// find group name by group id
|
||||
int ObCgroupCtrl::get_group_info_by_group_id(
|
||||
const uint64_t tenant_id, uint64_t group_id, share::ObGroupName &group_name)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObResourceMappingRuleManager &rule_mgr = G_RES_MGR.get_mapping_rule_mgr();
|
||||
@ -472,7 +468,7 @@ int ObCgroupCtrl::get_cgroup_config_(const char *group_path, const char *config_
|
||||
bool exist_cgroup = false;
|
||||
if (OB_FAIL(FileDirectoryUtils::is_exists(group_path, exist_cgroup))) {
|
||||
LOG_WARN("fail check file exist", K(group_path), K(ret));
|
||||
} else if (!exist_cgroup && OB_FAIL(init_full_dir_(group_path))) {
|
||||
} else if (!exist_cgroup) {
|
||||
LOG_WARN("init tenant cgroup dir failed", K(ret), K(group_path));
|
||||
} else if (OB_FAIL(get_string_from_file_(cgroup_config_path, config_value))) {
|
||||
LOG_WARN("get cgroup config value failed", K(ret), K(cgroup_config_path), K(config_value));
|
||||
@ -485,7 +481,6 @@ int ObCgroupCtrl::set_cgroup_config_(const char *group_path, const char *config_
|
||||
int ret = OB_SUCCESS;
|
||||
char config_path[PATH_BUFSIZE];
|
||||
snprintf(config_path, PATH_BUFSIZE, "%s/%s", group_path, config_name);
|
||||
|
||||
bool exist_cgroup = false;
|
||||
if (OB_FAIL(FileDirectoryUtils::is_exists(group_path, exist_cgroup))) {
|
||||
LOG_WARN("fail check file exist", K(group_path), K(ret));
|
||||
@ -497,10 +492,8 @@ int ObCgroupCtrl::set_cgroup_config_(const char *group_path, const char *config_
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObCgroupCtrl::set_cpu_shares(const uint64_t tenant_id,
|
||||
const double cpu,
|
||||
const uint64_t group_id,
|
||||
const char *base_path)
|
||||
int ObCgroupCtrl::set_cpu_shares_(
|
||||
const uint64_t tenant_id, const double cpu, const uint64_t group_id, const bool is_background)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
char group_path[PATH_BUFSIZE];
|
||||
@ -508,39 +501,45 @@ int ObCgroupCtrl::set_cpu_shares(const uint64_t tenant_id,
|
||||
|
||||
int32_t cpu_shares = static_cast<int32_t>(cpu * DEFAULT_CPU_SHARES);
|
||||
snprintf(cpu_shares_value, VALUE_BUFSIZE, "%d", cpu_shares);
|
||||
if (OB_FAIL(get_group_path(group_path, PATH_BUFSIZE, tenant_id, group_id, base_path))) {
|
||||
if (OB_FAIL(get_group_path(group_path, PATH_BUFSIZE, tenant_id, group_id, is_background))) {
|
||||
LOG_WARN("fail get group path", K(tenant_id), K(ret));
|
||||
} else if (OB_FAIL(set_cgroup_config_(group_path, CPU_SHARES_FILE, cpu_shares_value))) {
|
||||
LOG_WARN("set cpu shares failed", K(ret), K(group_path), K(tenant_id));
|
||||
} else {
|
||||
LOG_INFO("set cpu shares success",
|
||||
K(group_path), K(cpu), K(cpu_shares_value), K(tenant_id));
|
||||
LOG_INFO("set cpu shares success", K(group_path), K(cpu), K(cpu_shares_value), K(tenant_id));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int ObCgroupCtrl::set_both_cpu_shares(const uint64_t tenant_id,
|
||||
const double cpu,
|
||||
const uint64_t group_id,
|
||||
const char *base_path)
|
||||
int ObCgroupCtrl::set_cpu_shares(
|
||||
const uint64_t tenant_id, const double cpu, const uint64_t group_id, const bool is_background)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(set_cpu_shares(tenant_id, cpu, group_id))) {
|
||||
LOG_WARN("set cpu shares failed", K(ret), K(tenant_id), K(group_id), K(cpu));
|
||||
} else if (OB_NOT_NULL(base_path) && 0 != STRLEN(base_path) && OB_FAIL(set_cpu_shares(tenant_id, cpu, group_id, base_path))) {
|
||||
LOG_WARN("set background cpu shares failed", K(ret), K(tenant_id), K(group_id), K(cpu));
|
||||
if (!(is_background && GCONF.enable_global_background_resource_isolation)) {
|
||||
if (OB_FAIL(set_cpu_shares_(tenant_id, cpu, group_id, false /* is_background */))) {
|
||||
LOG_WARN("remove tenant cgroup directory failed", K(ret), K(tenant_id));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret) && GCONF.enable_global_background_resource_isolation) {
|
||||
if (OB_FAIL(set_cpu_shares_(tenant_id, cpu, group_id, true /* is_background */))) {
|
||||
LOG_WARN("remove background tenant cgroup directory failed", K(ret), K(tenant_id));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObCgroupCtrl::get_cpu_shares(const uint64_t tenant_id, double &cpu, const uint64_t group_id, const char *base_path)
|
||||
int ObCgroupCtrl::get_cpu_shares(
|
||||
const uint64_t tenant_id, double &cpu, const uint64_t group_id, const bool is_background)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
char group_path[PATH_BUFSIZE];
|
||||
char cpu_shares_value[VALUE_BUFSIZE + 1];
|
||||
|
||||
if (OB_FAIL(get_group_path(group_path, PATH_BUFSIZE, tenant_id, group_id, base_path))) {
|
||||
if (OB_FAIL(get_group_path(group_path,
|
||||
PATH_BUFSIZE,
|
||||
tenant_id,
|
||||
group_id,
|
||||
is_background && GCONF.enable_global_background_resource_isolation))) {
|
||||
LOG_WARN("fail get group path", K(tenant_id), K(ret));
|
||||
} else if (OB_FAIL(get_cgroup_config_(group_path, CPU_SHARES_FILE, cpu_shares_value))) {
|
||||
LOG_WARN("get cpu shares failed", K(ret), K(group_path), K(tenant_id));
|
||||
@ -551,7 +550,8 @@ int ObCgroupCtrl::get_cpu_shares(const uint64_t tenant_id, double &cpu, const ui
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObCgroupCtrl::compare_cpu(const double cpu1, const double cpu2, int &compare_ret) {
|
||||
int ObCgroupCtrl::compare_cpu(const double cpu1, const double cpu2, int &compare_ret)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
compare_ret = 0;
|
||||
if (cpu1 != cpu2) {
|
||||
@ -566,7 +566,8 @@ int ObCgroupCtrl::compare_cpu(const double cpu1, const double cpu2, int &compare
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObCgroupCtrl::set_cpu_cfs_quota(const uint64_t tenant_id, const double cpu, const uint64_t group_id, const char *base_path)
|
||||
int ObCgroupCtrl::set_cpu_cfs_quota_(
|
||||
const uint64_t tenant_id, const double cpu, const uint64_t group_id, const bool is_background)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
|
||||
@ -574,9 +575,9 @@ int ObCgroupCtrl::set_cpu_cfs_quota(const uint64_t tenant_id, const double cpu,
|
||||
double base_cpu = -1;
|
||||
|
||||
// background quota limit
|
||||
if (is_valid_tenant_id(tenant_id) && OB_NOT_NULL(base_path) && 0 != STRLEN(base_path)) {
|
||||
if (is_valid_tenant_id(tenant_id) && is_background) {
|
||||
int compare_ret = 0;
|
||||
if (OB_FAIL(get_cpu_cfs_quota(OB_INVALID_TENANT_ID, base_cpu, OB_INVALID_GROUP_ID, base_path))) {
|
||||
if (OB_FAIL(get_cpu_cfs_quota(OB_INVALID_TENANT_ID, base_cpu, OB_INVALID_GROUP_ID, is_background))) {
|
||||
LOG_WARN("get background cpu cfs quota failed", K(ret), K(tenant_id));
|
||||
} else if (OB_FAIL(compare_cpu(target_cpu, base_cpu, compare_ret))) {
|
||||
LOG_WARN("compare cpu failed", K(ret), K(target_cpu), K(base_cpu));
|
||||
@ -589,7 +590,7 @@ int ObCgroupCtrl::set_cpu_cfs_quota(const uint64_t tenant_id, const double cpu,
|
||||
double tenant_cpu = -1;
|
||||
if (OB_SUCC(ret) && is_valid_group(group_id)) {
|
||||
int compare_ret = 0;
|
||||
if (OB_FAIL(get_cpu_cfs_quota(tenant_id, tenant_cpu, OB_INVALID_GROUP_ID, base_path))) {
|
||||
if (OB_FAIL(get_cpu_cfs_quota(tenant_id, tenant_cpu, OB_INVALID_GROUP_ID, is_background))) {
|
||||
LOG_WARN("get tenant cpu cfs quota failed", K(ret), K(tenant_id));
|
||||
} else if (OB_FAIL(compare_cpu(target_cpu, tenant_cpu, compare_ret))) {
|
||||
LOG_WARN("compare cpu failed", K(ret), K(target_cpu), K(tenant_cpu));
|
||||
@ -602,9 +603,9 @@ int ObCgroupCtrl::set_cpu_cfs_quota(const uint64_t tenant_id, const double cpu,
|
||||
double current_cpu = -1;
|
||||
char group_path[PATH_BUFSIZE];
|
||||
int compare_ret = 0;
|
||||
if (OB_FAIL(get_cpu_cfs_quota(tenant_id, current_cpu, group_id, base_path))) {
|
||||
if (OB_FAIL(get_cpu_cfs_quota(tenant_id, current_cpu, group_id, is_background))) {
|
||||
LOG_WARN("get cpu cfs quota failed", K(ret), K(group_path), K(tenant_id), K(group_id));
|
||||
} else if (OB_FAIL(get_group_path(group_path, PATH_BUFSIZE, tenant_id, group_id, base_path))) {
|
||||
} else if (OB_FAIL(get_group_path(group_path, PATH_BUFSIZE, tenant_id, group_id, is_background))) {
|
||||
LOG_WARN("get group path failed", K(ret), K(group_path), K(tenant_id), K(group_id));
|
||||
} else if (OB_FAIL(compare_cpu(target_cpu, current_cpu, compare_ret))) {
|
||||
LOG_WARN("compare cpu failed", K(ret), K(target_cpu), K(current_cpu));
|
||||
@ -624,38 +625,40 @@ int ObCgroupCtrl::set_cpu_cfs_quota(const uint64_t tenant_id, const double cpu,
|
||||
K(target_cpu),
|
||||
K(current_cpu),
|
||||
K(group_path));
|
||||
} else {
|
||||
LOG_INFO(
|
||||
"set cpu cfs quota success", K(tenant_id), K(group_id), K(cpu), K(target_cpu), K(current_cpu), K(group_path));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
class DecQuotaProcessor : public ObCgroupCtrl::DirProcessor
|
||||
{
|
||||
public:
|
||||
DecQuotaProcessor(const double cpu) : cpu_(cpu)
|
||||
{}
|
||||
int handle_dir(const char *curr_path, bool is_top_dir)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
double current_cpu = -1;
|
||||
int compare_ret = 0;
|
||||
if (OB_FAIL(ObCgroupCtrl::get_cpu_cfs_quota_by_path_(curr_path, current_cpu))) {
|
||||
LOG_WARN("get cpu cfs quota failed", K(ret), K(curr_path));
|
||||
} else if ((!is_top_dir && -1 == current_cpu) ||
|
||||
(OB_SUCC(ObCgroupCtrl::compare_cpu(cpu_, current_cpu, compare_ret)) && compare_ret >= 0)) {
|
||||
// do nothing
|
||||
} else if (OB_FAIL(ObCgroupCtrl::set_cpu_cfs_quota_by_path_(curr_path, cpu_))) {
|
||||
LOG_WARN("set cpu cfs quota failed", K(curr_path), K(cpu_));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private:
|
||||
const double cpu_;
|
||||
};
|
||||
|
||||
int ObCgroupCtrl::recursion_dec_cpu_cfs_quota_(const char *group_path, const double cpu)
|
||||
{
|
||||
class DecQuotaProcessor : public ObCgroupCtrl::DirProcessor
|
||||
{
|
||||
public:
|
||||
DecQuotaProcessor(const double cpu) : cpu_(cpu)
|
||||
{}
|
||||
int handle_dir(const char *curr_path, bool is_top_dir)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
double current_cpu = -1;
|
||||
int compare_ret = 0;
|
||||
if (OB_FAIL(ObCgroupCtrl::get_cpu_cfs_quota_by_path_(curr_path, current_cpu))) {
|
||||
LOG_WARN("get cpu cfs quota failed", K(ret), K(curr_path));
|
||||
} else if ((!is_top_dir && -1 == current_cpu) ||
|
||||
(OB_SUCC(ObCgroupCtrl::compare_cpu(cpu_, current_cpu, compare_ret)) && compare_ret >= 0)) {
|
||||
// do nothing
|
||||
} else if (OB_FAIL(ObCgroupCtrl::set_cpu_cfs_quota_by_path_(curr_path, cpu_))) {
|
||||
LOG_WARN("set cpu cfs quota failed", K(curr_path), K(cpu_));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private:
|
||||
const double cpu_;
|
||||
};
|
||||
DecQuotaProcessor dec_quota_process(cpu);
|
||||
return recursion_process_group_(group_path, &dec_quota_process, true /* is_top_dir */);
|
||||
}
|
||||
@ -734,22 +737,33 @@ int ObCgroupCtrl::get_cpu_cfs_quota_by_path_(const char *group_path, double &cpu
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObCgroupCtrl::set_both_cpu_cfs_quota(const uint64_t tenant_id, const double cpu, const uint64_t group_id, const char *base_path)
|
||||
int ObCgroupCtrl::set_cpu_cfs_quota(
|
||||
const uint64_t tenant_id, const double cpu, const uint64_t group_id, const bool is_background)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(set_cpu_cfs_quota(tenant_id, cpu, group_id))) {
|
||||
LOG_WARN("set tenant cpu cfs quota failed", K(ret), K(tenant_id), K(group_id), K(cpu));
|
||||
} else if (OB_NOT_NULL(base_path) && 0 != STRLEN(base_path) && OB_FAIL(set_cpu_cfs_quota(tenant_id, cpu, group_id, base_path))) {
|
||||
LOG_WARN("set background tenant cpu cfs quota failed", K(ret), K(tenant_id), K(group_id), K(cpu));
|
||||
if (!(is_background && GCONF.enable_global_background_resource_isolation)) {
|
||||
if (OB_FAIL(set_cpu_cfs_quota_(tenant_id, cpu, group_id, false /* is_background */))) {
|
||||
LOG_WARN("set cpu quota failed", K(ret), K(tenant_id));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret) && GCONF.enable_global_background_resource_isolation) {
|
||||
if (OB_FAIL(set_cpu_cfs_quota_(tenant_id, cpu, group_id, true /* is_background */))) {
|
||||
LOG_WARN("set background cpu quota directory failed", K(ret), K(tenant_id));
|
||||
}
|
||||
}
|
||||
return OB_SUCCESS;
|
||||
}
|
||||
|
||||
int ObCgroupCtrl::get_cpu_cfs_quota(const uint64_t tenant_id, double &cpu, const uint64_t group_id, const char *base_path)
|
||||
int ObCgroupCtrl::get_cpu_cfs_quota(
|
||||
const uint64_t tenant_id, double &cpu, const uint64_t group_id, const bool is_background)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
char group_path[PATH_BUFSIZE];
|
||||
if (OB_FAIL(get_group_path(group_path, PATH_BUFSIZE, tenant_id, group_id, base_path))) {
|
||||
if (OB_FAIL(get_group_path(group_path,
|
||||
PATH_BUFSIZE,
|
||||
tenant_id,
|
||||
group_id,
|
||||
is_background && GCONF.enable_global_background_resource_isolation))) {
|
||||
LOG_WARN("fail get group path", K(tenant_id), K(ret));
|
||||
} else if (OB_FAIL(get_cpu_cfs_quota_by_path_(group_path, cpu))) {
|
||||
LOG_WARN("get cpu cfs quota failed", K(ret), K(group_path), K(tenant_id));
|
||||
@ -757,14 +771,19 @@ int ObCgroupCtrl::get_cpu_cfs_quota(const uint64_t tenant_id, double &cpu, const
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObCgroupCtrl::get_cpu_time(const uint64_t tenant_id, int64_t &cpu_time, const uint64_t group_id, const char *base_path)
|
||||
int ObCgroupCtrl::get_cpu_time_(
|
||||
const uint64_t tenant_id, int64_t &cpu_time, const uint64_t group_id, const bool is_background)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
|
||||
char group_path[PATH_BUFSIZE];
|
||||
char cpuacct_usage_value[VALUE_BUFSIZE + 1];
|
||||
|
||||
if (OB_FAIL(get_group_path(group_path, PATH_BUFSIZE, tenant_id, group_id, base_path))) {
|
||||
if (OB_FAIL(get_group_path(group_path,
|
||||
PATH_BUFSIZE,
|
||||
tenant_id,
|
||||
group_id,
|
||||
is_background && GCONF.enable_global_background_resource_isolation))) {
|
||||
LOG_WARN("fail get group path", K(tenant_id), K(ret));
|
||||
} else if (OB_FAIL(get_cgroup_config_(group_path, CPUACCT_USAGE_FILE, cpuacct_usage_value))) {
|
||||
LOG_WARN("get cpuacct.usage failed", K(ret), K(group_path), K(tenant_id));
|
||||
@ -775,14 +794,35 @@ int ObCgroupCtrl::get_cpu_time(const uint64_t tenant_id, int64_t &cpu_time, cons
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObCgroupCtrl::get_throttled_time(const uint64_t tenant_id, int64_t &throttled_time, const uint64_t group_id, const char *base_path)
|
||||
int ObCgroupCtrl::get_cpu_time(const uint64_t tenant_id, int64_t &cpu_time, const uint64_t group_id)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
cpu_time = 0;
|
||||
if (OB_FAIL(get_cpu_time_(tenant_id, cpu_time, group_id, false /* is_background */))) {
|
||||
LOG_WARN("get cpu_time failed", K(ret), K(tenant_id), K(group_id));
|
||||
} else if (GCONF.enable_global_background_resource_isolation) {
|
||||
int64_t background_cpu_time = 0;
|
||||
if (OB_FAIL(get_cpu_time_(tenant_id, background_cpu_time, group_id, true /* is_background */))) {
|
||||
LOG_WARN("get background_cpu_time failed", K(ret), K(tenant_id), K(group_id));
|
||||
}
|
||||
cpu_time += background_cpu_time;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObCgroupCtrl::get_throttled_time_(
|
||||
const uint64_t tenant_id, int64_t &throttled_time, const uint64_t group_id, const bool is_background)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
|
||||
char group_path[PATH_BUFSIZE];
|
||||
char cpu_stat_value[VALUE_BUFSIZE + 1];
|
||||
|
||||
if (OB_FAIL(get_group_path(group_path, PATH_BUFSIZE, tenant_id, group_id, base_path))) {
|
||||
if (OB_FAIL(get_group_path(group_path,
|
||||
PATH_BUFSIZE,
|
||||
tenant_id,
|
||||
group_id,
|
||||
is_background && GCONF.enable_global_background_resource_isolation))) {
|
||||
LOG_WARN("fail get group path", K(tenant_id), K(ret));
|
||||
} else if (OB_FAIL(get_cgroup_config_(group_path, CPU_STAT_FILE, cpu_stat_value))) {
|
||||
LOG_WARN("get cpu.stat failed", K(ret), K(group_path), K(tenant_id));
|
||||
@ -801,6 +841,22 @@ int ObCgroupCtrl::get_throttled_time(const uint64_t tenant_id, int64_t &throttle
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObCgroupCtrl::get_throttled_time(const uint64_t tenant_id, int64_t &throttled_time, const uint64_t group_id)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
throttled_time = 0;
|
||||
if (OB_FAIL(get_throttled_time_(tenant_id, throttled_time, group_id, false /* is_background */))) {
|
||||
LOG_WARN("get throttled_time failed", K(ret), K(tenant_id), K(group_id));
|
||||
} else if (GCONF.enable_global_background_resource_isolation) {
|
||||
int64_t background_throttled_time = 0;
|
||||
if (OB_FAIL(get_throttled_time_(tenant_id, background_throttled_time, group_id, true /* is_background */))) {
|
||||
LOG_WARN("get background_throttled_time failed", K(ret), K(tenant_id), K(group_id));
|
||||
}
|
||||
throttled_time += background_throttled_time;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObCgroupCtrl::init_cgroup_root_dir_(const char *cgroup_path)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
|
@ -158,27 +158,16 @@ public:
|
||||
static int compare_cpu(const double cpu1, const double cpu2, int &compare_ret);
|
||||
|
||||
// 删除租户cgroup规则
|
||||
int remove_cgroup(const uint64_t tenant_id, const uint64_t group_id = OB_INVALID_GROUP_ID, const char *base_path = "");
|
||||
int remove_both_cgroup(const uint64_t tenant_id, const uint64_t group_id = OB_INVALID_GROUP_ID, const char *base_path = "");
|
||||
static int remove_dir_(const char *curr_dir, bool is_delete_group = false);
|
||||
|
||||
static int get_cgroup_config_(const char *group_path, const char *config_name, char *config_value);
|
||||
static int set_cgroup_config_(const char *group_path, const char *config_name, char *config_value);
|
||||
int remove_cgroup(const uint64_t tenant_id, const uint64_t group_id = OB_INVALID_GROUP_ID, const bool is_background = false);
|
||||
// 设定指定租户cgroup组的cpu.shares
|
||||
int set_cpu_shares(const uint64_t tenant_id, const double cpu, const uint64_t group_id = OB_INVALID_GROUP_ID, const char *base_path = "");
|
||||
int set_both_cpu_shares(const uint64_t tenant_id, const double cpu, const uint64_t group_id = OB_INVALID_GROUP_ID, const char *base_path = "");
|
||||
int get_cpu_shares(const uint64_t tenant_id, double &cpu, const uint64_t group_id = OB_INVALID_GROUP_ID, const char *base_path = "");
|
||||
int set_cpu_shares(const uint64_t tenant_id, const double cpu, const uint64_t group_id = OB_INVALID_GROUP_ID, const bool is_background = false);
|
||||
int get_cpu_shares(const uint64_t tenant_id, double &cpu, const uint64_t group_id = OB_INVALID_GROUP_ID, const bool is_background = false);
|
||||
// 设定指定租户cgroup组的cpu.cfs_quota_us
|
||||
int set_cpu_cfs_quota(const uint64_t tenant_id, const double cpu, const uint64_t group_id = OB_INVALID_GROUP_ID, const char *base_path = "");
|
||||
static int set_cpu_cfs_quota_by_path_(const char *group_path, const double cpu);
|
||||
static int get_cpu_cfs_quota_by_path_(const char *group_path, double &cpu);
|
||||
static int dec_cpu_cfs_quota_(const char *curr_path, const double cpu);
|
||||
int recursion_dec_cpu_cfs_quota_(const char *curr_path, const double cpu);
|
||||
int set_both_cpu_cfs_quota(const uint64_t tenant_id, const double cpu, const uint64_t group_id = OB_INVALID_GROUP_ID, const char *base_path = "");
|
||||
int get_cpu_cfs_quota(const uint64_t tenant_id, double &cpu, const uint64_t group_id = OB_INVALID_GROUP_ID, const char *base_path = "");
|
||||
int set_cpu_cfs_quota(const uint64_t tenant_id, const double cpu, const uint64_t group_id = OB_INVALID_GROUP_ID, const bool is_background = false);
|
||||
int get_cpu_cfs_quota(const uint64_t tenant_id, double &cpu, const uint64_t group_id = OB_INVALID_GROUP_ID, const bool is_background = false);
|
||||
// 获取某个cgroup组的cpuacct.usage, 即cpu time
|
||||
int get_cpu_time(const uint64_t tenant_id, int64_t &cpu_time, const uint64_t group_id = OB_INVALID_GROUP_ID, const char *base_path = "");
|
||||
int get_throttled_time(const uint64_t tenant_id, int64_t &throttled_time, const uint64_t group_id = OB_INVALID_GROUP_ID, const char *base_path = "");
|
||||
int get_cpu_time(const uint64_t tenant_id, int64_t &cpu_time, const uint64_t group_id = OB_INVALID_GROUP_ID);
|
||||
int get_throttled_time(const uint64_t tenant_id, int64_t &throttled_time, const uint64_t group_id = OB_INVALID_GROUP_ID);
|
||||
int get_group_info_by_group_id(const uint64_t tenant_id,
|
||||
uint64_t group_id,
|
||||
share::ObGroupName &group_name);
|
||||
@ -188,7 +177,7 @@ public:
|
||||
public:
|
||||
DirProcessor() = default;
|
||||
~DirProcessor() = default;
|
||||
virtual int handle_dir(const char *group_path, bool is_top_dir=false) = 0;
|
||||
virtual int handle_dir(const char *group_path, const bool is_top_dir=false) = 0;
|
||||
};
|
||||
|
||||
private:
|
||||
@ -220,11 +209,23 @@ private:
|
||||
int path_bufsize,
|
||||
const uint64_t tenant_id,
|
||||
uint64_t group_id = OB_INVALID_GROUP_ID,
|
||||
const char *base_path = "");
|
||||
const bool is_background = false);
|
||||
enum { NOT_DIR = 0, LEAF_DIR, REGULAR_DIR };
|
||||
int which_type_dir_(const char *curr_path, int &result);
|
||||
int recursion_remove_group_(const char *curr_path);
|
||||
int recursion_process_group_(const char *curr_path, DirProcessor *processor_ptr, bool is_top_dir = false);
|
||||
int remove_cgroup_(const uint64_t tenant_id, const uint64_t group_id = OB_INVALID_GROUP_ID, const bool is_background = false);
|
||||
static int remove_dir_(const char *curr_dir, bool is_delete_group = false);
|
||||
static int get_cgroup_config_(const char *group_path, const char *config_name, char *config_value);
|
||||
static int set_cgroup_config_(const char *group_path, const char *config_name, char *config_value);
|
||||
int set_cpu_shares_(const uint64_t tenant_id, const double cpu, const uint64_t group_id = OB_INVALID_GROUP_ID, const bool is_background = false);
|
||||
int set_cpu_cfs_quota_(const uint64_t tenant_id, const double cpu, const uint64_t group_id = OB_INVALID_GROUP_ID, const bool is_background = false);
|
||||
static int set_cpu_cfs_quota_by_path_(const char *group_path, const double cpu);
|
||||
static int get_cpu_cfs_quota_by_path_(const char *group_path, double &cpu);
|
||||
static int dec_cpu_cfs_quota_(const char *curr_path, const double cpu);
|
||||
int recursion_dec_cpu_cfs_quota_(const char *curr_path, const double cpu);
|
||||
int get_cpu_time_(const uint64_t tenant_id, int64_t &cpu_time, const uint64_t group_id = OB_INVALID_GROUP_ID, const bool is_background = false);
|
||||
int get_throttled_time_(const uint64_t tenant_id, int64_t &throttled_time, const uint64_t group_id = OB_INVALID_GROUP_ID, const bool is_background = false);
|
||||
};
|
||||
|
||||
} // share
|
||||
|
@ -114,7 +114,7 @@ int ObResourceMappingRuleManager::clear_deleted_group(
|
||||
uint64_t deleted_group_id = group_id_keys.at(i).group_id_;
|
||||
ObGroupName deleted_group_name = group_names.at(i);
|
||||
LOG_INFO("group_id need to be cleared", K(tenant_id), K(deleted_group_id), K(deleted_group_name));
|
||||
if (OB_FAIL(GCTX.cgroup_ctrl_->remove_both_cgroup(tenant_id, deleted_group_id))) {
|
||||
if (OB_FAIL(GCTX.cgroup_ctrl_->remove_cgroup(tenant_id, deleted_group_id))) {
|
||||
LOG_WARN("failed to remove cgroup", K(ret), K(tenant_id), K(deleted_group_id));
|
||||
} else if (OB_FAIL(tenant_holder.get_ptr()->delete_consumer_group_config(deleted_group_id))) {
|
||||
LOG_WARN("delete consumer group config failed", K(ret), K(tenant_id), K(deleted_group_id));
|
||||
|
@ -72,28 +72,27 @@ int ObResourcePlanManager::switch_resource_plan(const uint64_t tenant_id, ObStri
|
||||
int ObResourcePlanManager::refresh_global_background_cpu()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int32_t cfs_period_us = 0;
|
||||
if (GCONF.enable_global_background_resource_isolation) {
|
||||
double cpu = static_cast<double>(GCONF.global_background_cpu_quota);
|
||||
if (cpu <= 0) {
|
||||
cpu = -1;
|
||||
}
|
||||
if (cpu >= 0 && OB_FAIL(GCTX.cgroup_ctrl_->set_cpu_shares( // set cgroup/background/cpu.shares
|
||||
OB_INVALID_TENANT_ID,
|
||||
cpu,
|
||||
OB_INVALID_GROUP_ID,
|
||||
BACKGROUND_CGROUP))) {
|
||||
LOG_WARN("fail to set background cpu shares", K(ret));
|
||||
OB_INVALID_TENANT_ID,
|
||||
cpu,
|
||||
OB_INVALID_GROUP_ID,
|
||||
true /* is_background */))) {
|
||||
LOG_WARN("fail to set background cpu shares", K(ret));
|
||||
}
|
||||
int compare_ret = 0;
|
||||
if (OB_SUCC(ret) && OB_SUCC(GCTX.cgroup_ctrl_->compare_cpu(background_quota_, cpu, compare_ret))) {
|
||||
if (0 == compare_ret) {
|
||||
// do nothing
|
||||
} else if (OB_FAIL(GCTX.cgroup_ctrl_->set_cpu_cfs_quota( // set cgroup/background/cpu.cfs_quota_us
|
||||
OB_INVALID_TENANT_ID,
|
||||
cpu,
|
||||
OB_INVALID_GROUP_ID,
|
||||
BACKGROUND_CGROUP))) {
|
||||
OB_INVALID_TENANT_ID,
|
||||
cpu,
|
||||
OB_INVALID_GROUP_ID,
|
||||
true /* is_background */))) {
|
||||
LOG_WARN("fail to set background cpu cfs quota", K(ret));
|
||||
} else {
|
||||
if (compare_ret < 0) {
|
||||
@ -114,18 +113,16 @@ int ObResourcePlanManager::refresh_global_background_cpu()
|
||||
} else if (compare_ret > 0) {
|
||||
target_cpu = cpu;
|
||||
}
|
||||
if (OB_TMP_FAIL(GCTX.cgroup_ctrl_->set_cpu_cfs_quota(tenant_id,
|
||||
target_cpu,
|
||||
OB_INVALID_GROUP_ID,
|
||||
BACKGROUND_CGROUP))) {
|
||||
if (OB_TMP_FAIL(GCTX.cgroup_ctrl_->set_cpu_cfs_quota(
|
||||
tenant_id, target_cpu, OB_INVALID_GROUP_ID, true /* is_background */))) {
|
||||
LOG_WARN_RET(tmp_ret, "set tenant cpu cfs quota failed", K(tmp_ret), K(tenant_id));
|
||||
} else if (OB_TMP_FAIL(GCTX.cgroup_ctrl_->set_cpu_cfs_quota(
|
||||
tenant_id, target_cpu, USER_RESOURCE_OTHER_GROUP_ID, BACKGROUND_CGROUP))) {
|
||||
tenant_id, target_cpu, USER_RESOURCE_OTHER_GROUP_ID, true /* is_background */))) {
|
||||
LOG_WARN_RET(tmp_ret, "set tenant cpu cfs quota failed", K(ret), K(tenant_id));
|
||||
} else if (is_user_tenant(tenant_id)) {
|
||||
uint64_t meta_tenant_id = gen_meta_tenant_id(tenant_id);
|
||||
if (OB_TMP_FAIL(GCTX.cgroup_ctrl_->set_cpu_cfs_quota(
|
||||
meta_tenant_id, target_cpu, OB_INVALID_GROUP_ID, BACKGROUND_CGROUP))) {
|
||||
meta_tenant_id, target_cpu, OB_INVALID_GROUP_ID, true /* is_background */))) {
|
||||
LOG_WARN_RET(tmp_ret, "set tenant cpu cfs quota failed", K(tmp_ret), K(meta_tenant_id));
|
||||
}
|
||||
}
|
||||
@ -329,29 +326,28 @@ int ObResourcePlanManager::flush_directive_to_cgroup_fs(ObPlanDirectiveSet &dire
|
||||
int ret = OB_SUCCESS;
|
||||
for (int64_t i = 0; i < directives.count(); ++i) {
|
||||
const ObPlanDirective &d = directives.at(i);
|
||||
if (OB_FAIL(GCTX.cgroup_ctrl_->set_both_cpu_shares(d.tenant_id_,
|
||||
d.mgmt_p1_ / 100,
|
||||
d.group_id_,
|
||||
GCONF.enable_global_background_resource_isolation ? BACKGROUND_CGROUP : ""))) {
|
||||
if (OB_FAIL(GCTX.cgroup_ctrl_->set_cpu_shares(d.tenant_id_, d.mgmt_p1_ / 100, d.group_id_))) {
|
||||
LOG_ERROR("fail set cpu shares. tenant isolation function may not functional!!", K(d), K(ret));
|
||||
} else {
|
||||
double tenant_cpu_quota = 0;
|
||||
if (OB_FAIL(GCTX.cgroup_ctrl_->get_cpu_cfs_quota(d.tenant_id_, tenant_cpu_quota, OB_INVALID_GROUP_ID))) {
|
||||
LOG_WARN("fail get cpu quota", K(d), K(ret));
|
||||
} else if (OB_FAIL(GCTX.cgroup_ctrl_->set_cpu_cfs_quota(d.tenant_id_,
|
||||
-1 == tenant_cpu_quota ? -1 : tenant_cpu_quota * d.utilization_limit_ / 100,
|
||||
d.group_id_))) {
|
||||
LOG_ERROR("fail set cpu quota. tenant isolation function may not functional!!", K(ret), K(d), K(tenant_cpu_quota));
|
||||
-1 == tenant_cpu_quota ? -1 : tenant_cpu_quota * d.utilization_limit_ / 100,
|
||||
d.group_id_))) {
|
||||
LOG_ERROR(
|
||||
"fail set cpu quota. tenant isolation function may not functional!!", K(ret), K(d), K(tenant_cpu_quota));
|
||||
}
|
||||
if (OB_SUCC(ret) && GCONF.enable_global_background_resource_isolation) {
|
||||
if (OB_FAIL(GCTX.cgroup_ctrl_->get_cpu_cfs_quota(
|
||||
d.tenant_id_, tenant_cpu_quota, OB_INVALID_GROUP_ID, BACKGROUND_CGROUP))) {
|
||||
d.tenant_id_, tenant_cpu_quota, OB_INVALID_GROUP_ID, true /* is_background */))) {
|
||||
LOG_WARN("fail get cpu quota", K(d), K(ret));
|
||||
} else if (OB_FAIL(GCTX.cgroup_ctrl_->set_cpu_cfs_quota(d.tenant_id_,
|
||||
-1 == tenant_cpu_quota ? -1 : tenant_cpu_quota * d.utilization_limit_ / 100,
|
||||
d.group_id_,
|
||||
BACKGROUND_CGROUP))) {
|
||||
LOG_ERROR("fail set cpu quota. tenant isolation function may not functional!!", K(ret), K(d), K(tenant_cpu_quota));
|
||||
-1 == tenant_cpu_quota ? -1 : tenant_cpu_quota * d.utilization_limit_ / 100,
|
||||
d.group_id_,
|
||||
true /* is_background */))) {
|
||||
LOG_ERROR(
|
||||
"fail set cpu quota. tenant isolation function may not functional!!", K(ret), K(d), K(tenant_cpu_quota));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -452,17 +448,11 @@ int ObResourcePlanManager::clear_deleted_directives(const uint64_t tenant_id,
|
||||
LOG_INFO("directive need to be cleared", K(tenant_id), K(deleted_group_id));
|
||||
if (OB_FAIL(tenant_holder.get_ptr()->reset_consumer_group_config(deleted_group_id))) {
|
||||
LOG_WARN("reset consumer group config failed", K(ret), K(deleted_group_id));
|
||||
} else if (GCTX.cgroup_ctrl_->is_valid() &&
|
||||
OB_FAIL(GCTX.cgroup_ctrl_->set_both_cpu_shares(tenant_id,
|
||||
1,
|
||||
deleted_group_id,
|
||||
GCONF.enable_global_background_resource_isolation ? BACKGROUND_CGROUP : ""))) {
|
||||
} else if (!GCTX.cgroup_ctrl_->is_valid()) {
|
||||
// do nothing
|
||||
} else if (OB_FAIL(GCTX.cgroup_ctrl_->set_cpu_shares(tenant_id, 1, deleted_group_id))) {
|
||||
LOG_WARN("fail to set cpu share", K(ret), K(tenant_id), K(deleted_group_id));
|
||||
} else if (GCTX.cgroup_ctrl_->is_valid() &&
|
||||
OB_FAIL(GCTX.cgroup_ctrl_->set_both_cpu_cfs_quota(tenant_id,
|
||||
-1,
|
||||
deleted_group_id,
|
||||
GCONF.enable_global_background_resource_isolation ? BACKGROUND_CGROUP : ""))) {
|
||||
} else if (OB_FAIL(GCTX.cgroup_ctrl_->set_cpu_cfs_quota(tenant_id, -1, deleted_group_id))) {
|
||||
LOG_WARN("fail to set cpu quota", K(ret), K(tenant_id), K(deleted_group_id));
|
||||
}
|
||||
}
|
||||
|
@ -61,15 +61,15 @@ TEST(TestCgroupCtrl, SetGetValue)
|
||||
}
|
||||
sleep(1);
|
||||
|
||||
const int32_t cpu_shares = 2048;
|
||||
int32_t cpu_shares_v = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, cg_ctrl.set_both_cpu_shares(1001, cpu_shares));
|
||||
const double cpu_shares = 2048;
|
||||
double cpu_shares_v = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, cg_ctrl.set_cpu_shares(1001, cpu_shares));
|
||||
ASSERT_EQ(OB_SUCCESS, cg_ctrl.get_cpu_shares(1001, cpu_shares_v));
|
||||
ASSERT_EQ(cpu_shares, cpu_shares_v);
|
||||
|
||||
const int32_t cpu_cfs_quota = 80000;
|
||||
int32_t cpu_cfs_quota_v = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, cg_ctrl.set_both_cpu_cfs_quota(1001, cpu_cfs_quota));
|
||||
const double cpu_cfs_quota = 80000;
|
||||
double cpu_cfs_quota_v = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, cg_ctrl.set_cpu_cfs_quota(1001, cpu_cfs_quota));
|
||||
ASSERT_EQ(OB_SUCCESS, cg_ctrl.get_cpu_cfs_quota(1001, cpu_cfs_quota_v));
|
||||
ASSERT_EQ(cpu_cfs_quota, cpu_cfs_quota_v);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user