From 2cfa34045287fd6a822497a5b1c9fb460ec2d6db Mon Sep 17 00:00:00 2001 From: nroskill Date: Fri, 6 Jan 2023 11:15:32 +0000 Subject: [PATCH] fix wrong cpu_capacity in __all_virtual_server after cpu_count changing --- mittest/mtlenv/mock_tenant_module_env.h | 4 ++-- src/observer/ob_heartbeat.cpp | 3 +-- src/observer/ob_server.cpp | 17 ----------------- src/observer/ob_server_reload_config.cpp | 4 ---- src/observer/omt/ob_multi_tenant.cpp | 18 +----------------- src/observer/omt/ob_multi_tenant.h | 16 ---------------- .../virtual_table/ob_all_virtual_server.cpp | 2 +- .../blocksstable/test_block_manager.cpp | 3 ++- .../storage/mockcontainer/mock_ob_server.cpp | 3 ++- 9 files changed, 9 insertions(+), 61 deletions(-) diff --git a/mittest/mtlenv/mock_tenant_module_env.h b/mittest/mtlenv/mock_tenant_module_env.h index e21eec6d1..cb4424d56 100644 --- a/mittest/mtlenv/mock_tenant_module_env.h +++ b/mittest/mtlenv/mock_tenant_module_env.h @@ -547,7 +547,7 @@ int MockTenantModuleEnv::init_before_start_mtl() const int64_t ts_ns = ObTimeUtility::current_time_ns(); env_dir_ = "./env_" + std::to_string(rpc_port_) + "_" + std::to_string(ts_ns); run_dir_ = "./run_" + std::to_string(rpc_port_) + "_" + std::to_string(ts_ns); - + GCONF.cpu_count = 2; uint64_t start_time = 10000000; scramble_rand_.init(static_cast(start_time), static_cast(start_time / 2)); if (OB_FAIL(init_dir())) { @@ -581,7 +581,7 @@ int MockTenantModuleEnv::init_before_start_mtl() STORAGE_LOG(WARN, "fail to init env", K(ret)); } else if (OB_FAIL(ObServerCheckpointSlogHandler::get_instance().init())) { STORAGE_LOG(ERROR, "init server checkpoint slog handler fail", K(ret)); - } else if (OB_FAIL(multi_tenant_.init(self_addr_, 2, 2, nullptr, false))) { + } else if (OB_FAIL(multi_tenant_.init(self_addr_, nullptr, false))) { STORAGE_LOG(WARN, "fail to init env", K(ret)); } else if (OB_FAIL(sql_engine_.get_plan_cache_manager()->get_plan_cache_map().create(hash::cal_next_prime(512), ObModIds::OB_HASH_BUCKET_PLAN_CACHE, diff --git a/src/observer/ob_heartbeat.cpp b/src/observer/ob_heartbeat.cpp index 33649956a..acce087fa 100644 --- a/src/observer/ob_heartbeat.cpp +++ b/src/observer/ob_heartbeat.cpp @@ -102,8 +102,7 @@ int ObHeartBeatProcess::init_lease_request(ObLeaseRequest &lease_request) lease_request.zone_ = gctx_.config_->zone.str(); lease_request.server_ = gctx_.self_addr(); lease_request.sql_port_ = gctx_.config_->mysql_port; - lease_request.resource_info_.cpu_ - = gctx_.omt_->get_node_quota(); + lease_request.resource_info_.cpu_ = get_cpu_count(); lease_request.resource_info_.report_cpu_assigned_ = svr_res_assigned.min_cpu_; lease_request.resource_info_.report_cpu_max_assigned_ = svr_res_assigned.max_cpu_; lease_request.resource_info_.report_mem_assigned_ = svr_res_assigned.memory_size_; diff --git a/src/observer/ob_server.cpp b/src/observer/ob_server.cpp index 398d5dc69..70e76c999 100644 --- a/src/observer/ob_server.cpp +++ b/src/observer/ob_server.cpp @@ -1728,24 +1728,7 @@ int ObServer::init_multi_tenant() { int ret = OB_SUCCESS; - // get node cpu count from sysconf if node_cpu_count config isn't - // specified. - int64_t node_cpu_count = get_cpu_num(); - if (GCONF.cpu_count > "0") { - node_cpu_count = GCONF.cpu_count; - LOG_INFO("calc NODE CPU COUNT using config(node_cpu_count) for test", - K(node_cpu_count)); - } else { - LOG_INFO("calc NODE CPU COUNT using sysconf function", - K(node_cpu_count)); - } - - const int64_t cpu_count = node_cpu_count; - const int64_t times_of_workers = GCONF.workers_per_cpu_quota; - if (OB_FAIL(multi_tenant_.init(self_addr_, - static_cast(cpu_count), - times_of_workers, &sql_proxy_))) { LOG_ERROR("init multi tenant fail", KR(ret)); diff --git a/src/observer/ob_server_reload_config.cpp b/src/observer/ob_server_reload_config.cpp index 255ec06a9..d201b3229 100644 --- a/src/observer/ob_server_reload_config.cpp +++ b/src/observer/ob_server_reload_config.cpp @@ -246,10 +246,6 @@ int ObServerReloadConfig::operator()() share::ObTaskController::get().set_log_rate_limit( GCONF.syslog_io_bandwidth_limit.get_value()); - if (nullptr != GCTX.omt_) { - GCTX.omt_->set_workers_per_cpu(GCONF.workers_per_cpu_quota.get_value()); - } - get_unis_global_compat_version() = GET_MIN_CLUSTER_VERSION(); lib::g_runtime_enabled = true; diff --git a/src/observer/omt/ob_multi_tenant.cpp b/src/observer/omt/ob_multi_tenant.cpp index e78842d5e..fd3f25feb 100644 --- a/src/observer/omt/ob_multi_tenant.cpp +++ b/src/observer/omt/ob_multi_tenant.cpp @@ -208,14 +208,11 @@ ObMultiTenant::ObMultiTenant() bucket_lock_(), lock_(ObLatchIds::MULTI_TENANT_LOCK), tenants_(0, nullptr, ObModIds::OMT), - node_quota_(0), - times_of_workers_(0), balancer_(nullptr), myaddr_(), cpu_dump_(false), has_synced_(false) { - node_quota_ = DEFAULT_NODE_QUOTA; } static int init_compat_mode(lib::Worker::CompatMode &compat_mode) @@ -239,8 +236,6 @@ static int init_compat_mode(lib::Worker::CompatMode &compat_mode) } int ObMultiTenant::init(ObAddr myaddr, - double node_quota, - int64_t times_of_workers, ObMySQLProxy *sql_proxy, bool mtl_bind_flag) { @@ -251,16 +246,10 @@ int ObMultiTenant::init(ObAddr myaddr, LOG_WARN("ObMultiTenant has been inited", K(ret)); } else if (OB_FAIL(SLOGGERMGR.get_server_slogger(server_slogger_))) { LOG_WARN("fail to get server slogger", K(ret)); - } else if (node_quota <= 1 || times_of_workers < 1) { - ret = OB_INVALID_ARGUMENT; - LOG_ERROR("node quota should greater than 1 and times of workers should greater than or equal to 1", - K(ret), K(node_quota), K(times_of_workers), K(ret)); } else if (OB_FAIL(bucket_lock_.init(OB_TENANT_LOCK_BUCKET_NUM))) { LOG_WARN("fail to init bucket lock", K(ret)); } else { myaddr_ = myaddr; - node_quota_ = node_quota; - times_of_workers_ = times_of_workers; if (NULL != sql_proxy) { if (OB_FAIL(ObTenantNodeBalancer::get_instance().init(this, *sql_proxy, myaddr))) { @@ -713,7 +702,7 @@ int ObMultiTenant::create_tenant(const ObTenantMeta &meta, bool write_slog, cons ret = OB_NOT_INIT; LOG_WARN("group ctrl not init", K(ret)); } else if (OB_ISNULL(tenant = OB_NEW( - ObTenant, ObModIds::OMT, tenant_id, times_of_workers_, *GCTX.cgroup_ctrl_))) { + ObTenant, ObModIds::OMT, tenant_id, GCONF.workers_per_cpu_quota.get_value(), *GCTX.cgroup_ctrl_))) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("new tenant fail", K(ret)); } else if (FALSE_IT(create_step = ObTenantCreateStep::STEP_TENANT_NEWED)) { //step2 @@ -1901,11 +1890,6 @@ int ObMultiTenant::get_tenant_cpu( return ret; } -void ObMultiTenant::set_workers_per_cpu(int64_t v) -{ - times_of_workers_ = v; -} - void ObMultiTenant::set_group_sug_token() { int ret = OB_SUCCESS; diff --git a/src/observer/omt/ob_multi_tenant.h b/src/observer/omt/ob_multi_tenant.h index cc982c892..a543ddc93 100644 --- a/src/observer/omt/ob_multi_tenant.h +++ b/src/observer/omt/ob_multi_tenant.h @@ -80,16 +80,12 @@ class ObMultiTenant : public share::ObThreadPool { public: - const static int64_t DEFAULT_TIMES_OF_WORKERS = 10; const static int64_t TIME_SLICE_PERIOD = 10000; - constexpr static double DEFAULT_NODE_QUOTA = 16.; public: explicit ObMultiTenant(); int init(common::ObAddr myaddr, - double node_quota = DEFAULT_NODE_QUOTA, - int64_t times_of_workers = DEFAULT_TIMES_OF_WORKERS, common::ObMySQLProxy *sql_proxy = NULL, bool mtl_bind_flag = true); @@ -204,8 +200,6 @@ protected: mutable common::SpinRWLock lock_; // protect tenant list TenantList tenants_; - double node_quota_; - int64_t times_of_workers_; ObTenantNodeBalancer *balancer_; common::ObAddr myaddr_; bool cpu_dump_; @@ -222,16 +216,6 @@ TenantList &ObMultiTenant::get_tenant_list() return tenants_; } -double ObMultiTenant::get_node_quota() const -{ - return node_quota_; -} - -int64_t ObMultiTenant::get_times_of_workers() const -{ - return times_of_workers_; -} - int ObMultiTenant::lock_tenant_list(bool write) { int ret = common::OB_SUCCESS; diff --git a/src/observer/virtual_table/ob_all_virtual_server.cpp b/src/observer/virtual_table/ob_all_virtual_server.cpp index 8af9c15d7..7eb18a1e9 100644 --- a/src/observer/virtual_table/ob_all_virtual_server.cpp +++ b/src/observer/virtual_table/ob_all_virtual_server.cpp @@ -79,7 +79,7 @@ int ObAllVirtualServer::inner_get_next_row(ObNewRow *&row) } else { const int64_t col_count = output_column_ids_.count(); const double hard_limit = GCONF.resource_hard_limit; - const int64_t cpu_capacity = GCTX.omt_->get_node_quota(); + const int64_t cpu_capacity = get_cpu_count(); const double cpu_capacity_max = (cpu_capacity * hard_limit) / 100; const double cpu_assigned = svr_res_assigned.min_cpu_; const double cpu_assigned_max = svr_res_assigned.max_cpu_; diff --git a/unittest/storage/blocksstable/test_block_manager.cpp b/unittest/storage/blocksstable/test_block_manager.cpp index eae6fbd9f..e06f475e8 100644 --- a/unittest/storage/blocksstable/test_block_manager.cpp +++ b/unittest/storage/blocksstable/test_block_manager.cpp @@ -60,7 +60,8 @@ TestBlockManager::TestBlockManager() int TestBlockManager::init_multi_tenant() { int ret = OB_SUCCESS; - if (OB_SUCCESS != (ret = multi_tenant_.init(addr_, 6))) { + GCONF.cpu_count = 6; + if (OB_SUCCESS != (ret = multi_tenant_.init(addr_))) { STORAGE_LOG(WARN, "init multi_tenant failed", K(ret)); } else { multi_tenant_.start(); diff --git a/unittest/storage/mockcontainer/mock_ob_server.cpp b/unittest/storage/mockcontainer/mock_ob_server.cpp index 470b482bb..43b9a7690 100644 --- a/unittest/storage/mockcontainer/mock_ob_server.cpp +++ b/unittest/storage/mockcontainer/mock_ob_server.cpp @@ -242,8 +242,9 @@ int MockObServer::init(const char *schema_file, int MockObServer::init_multi_tenant() { int ret = OB_SUCCESS; + GCONF.cpu_count = 6; - if (OB_SUCCESS != (ret = multi_tenant_.init(self_addr_, 6))) { + if (OB_SUCCESS != (ret = multi_tenant_.init(self_addr_))) { STORAGE_LOG(WARN, "init multi_tenant failed", K(ret)); } else if (OB_SUCCESS != (ret = multi_tenant_.create_tenant_without_unit(OB_SYS_TENANT_ID, 3, 3))) { STORAGE_LOG(WARN, "add sys tenant failed", K(ret));