[part-2] Split plan memory to tenants

This commit is contained in:
obdev
2023-06-02 04:11:57 +00:00
committed by ob-robot
parent a7e3b054fd
commit 0e941a7b37
5 changed files with 25 additions and 13 deletions

View File

@ -430,7 +430,6 @@ void* ObTenantCtxAllocator::common_alloc(const int64_t size, const ObMemAttr &at
attr.tenant_id_, attr.ctx_id_, attr.tenant_id_, attr.ctx_id_,
get_global_ctx_info().get_ctx_name(attr.ctx_id_), get_global_ctx_info().get_ctx_name(attr.ctx_id_),
ta.get_hold(), ta.get_limit(), ta.get_tenant_hold(), ta.get_tenant_limit()); ta.get_hold(), ta.get_limit(), ta.get_tenant_hold(), ta.get_tenant_limit());
ObMallocAllocator::get_instance()->print_tenant_memory_usage(attr.tenant_id_);
// 49 is the user defined signal to dump memory // 49 is the user defined signal to dump memory
raise(49); raise(49);
} }

View File

@ -258,7 +258,13 @@ public:
template<typename ... Args> template<typename ... Args>
inline int prepare_allocate(int64_t capacity, Args && ... args) inline int prepare_allocate(int64_t capacity, Args && ... args)
{ {
return inner_prepare_allocate(capacity, args...); return inner_prepare_allocate(capacity, false, args...);
}
template<typename ... Args>
inline int prepare_allocate_and_keep_count(int64_t capacity, Args && ... args)
{
return inner_prepare_allocate(capacity, true, args...);
} }
inline ObFixedArrayImpl(const ObFixedArrayImpl<T, AllocatorT> &other) inline ObFixedArrayImpl(const ObFixedArrayImpl<T, AllocatorT> &other)
@ -281,7 +287,9 @@ public:
NEED_SERIALIZE_AND_DESERIALIZE; NEED_SERIALIZE_AND_DESERIALIZE;
private: private:
template<typename ... Args> template<typename ... Args>
inline int inner_prepare_allocate(int64_t capacity, Args && ... args) inline int inner_prepare_allocate(int64_t capacity,
const bool keep_count,
Args && ... args)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
if (capacity < 0 || capacity > UINT32_MAX) { if (capacity < 0 || capacity > UINT32_MAX) {
@ -294,7 +302,9 @@ private:
for (int64_t i = init_cnt_; i < capacity; i++) { for (int64_t i = init_cnt_; i < capacity; i++) {
new(&data_[i]) T(args...); new(&data_[i]) T(args...);
} }
count_ = static_cast<uint32_t>(capacity > count_ ? capacity : count_); if (!keep_count) {
count_ = static_cast<uint32_t>(capacity > count_ ? capacity : count_);
}
init_cnt_ = static_cast<uint32_t>(capacity >init_cnt_ ? capacity : init_cnt_); init_cnt_ = static_cast<uint32_t>(capacity >init_cnt_ ? capacity : init_cnt_);
} }
return ret; return ret;

View File

@ -777,9 +777,11 @@ int ObPhysicalPlan::set_table_locations(const ObTablePartitionInfoArray &infos,
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
table_locations_.reset(); table_locations_.reset();
das_table_locations_.reset(); das_table_locations_.reset();
if (OB_FAIL(table_locations_.init(infos.count()))) { if (OB_FAIL(table_locations_.prepare_allocate_and_keep_count(infos.count(),
allocator_))) {
LOG_WARN("fail to init table location count", K(ret)); LOG_WARN("fail to init table location count", K(ret));
} else if (OB_FAIL(das_table_locations_.init(infos.count()))) { } else if (OB_FAIL(das_table_locations_.prepare_allocate_and_keep_count(infos.count(),
allocator_))) {
LOG_WARN("fail to init das table location count", K(ret)); LOG_WARN("fail to init das table location count", K(ret));
} }
for (int64_t i = 0; OB_SUCC(ret) && i < infos.count(); ++i) { for (int64_t i = 0; OB_SUCC(ret) && i < infos.count(); ++i) {

View File

@ -48,7 +48,6 @@ namespace sql
{ {
ObPlanSet::~ObPlanSet() ObPlanSet::~ObPlanSet()
{ {
// Make sure destory planset before destory pre calculable expression. // Make sure destory planset before destory pre calculable expression.
if (OB_ISNULL(pre_cal_expr_handler_)) { if (OB_ISNULL(pre_cal_expr_handler_)) {
// have no pre calculable expression, do nothing // have no pre calculable expression, do nothing
@ -1186,7 +1185,7 @@ int ObSqlPlanSet::add_plan(ObPhysicalPlan &plan,
} else { } else {
if (OB_FAIL(add_physical_plan(OB_PHY_PLAN_LOCAL, pc_ctx, plan))) { if (OB_FAIL(add_physical_plan(OB_PHY_PLAN_LOCAL, pc_ctx, plan))) {
SQL_PC_LOG(TRACE, "fail to add local plan", K(ret)); SQL_PC_LOG(TRACE, "fail to add local plan", K(ret));
} else if (OB_SUCC(ret) } else if (OB_SUCC(ret)
&& FALSE_IT(direct_local_plan_ = &plan)) { && FALSE_IT(direct_local_plan_ = &plan)) {
// do nothing // do nothing
} else { } else {
@ -1281,6 +1280,9 @@ int ObSqlPlanSet::init_new_set(const ObPlanCacheCtx &pc_ctx,
LOG_WARN("pc_allocator has not been initialized.", K(ret)); LOG_WARN("pc_allocator has not been initialized.", K(ret));
} else if (OB_FAIL(ObPlanSet::init_new_set(pc_ctx, plan, outline_param_idx, pc_malloc_))) { } else if (OB_FAIL(ObPlanSet::init_new_set(pc_ctx, plan, outline_param_idx, pc_malloc_))) {
LOG_WARN("init new set failed", K(ret)); LOG_WARN("init new set failed", K(ret));
} else if (OB_FAIL(table_locations_.prepare_allocate_and_keep_count(sql_ctx.partition_infos_.count(),
*plan_cache_value_->get_pcv_set()->get_allocator()))) {
LOG_WARN("fail to init table location count", K(ret));
} else if (OB_FAIL(dist_plans_.init(this))) { } else if (OB_FAIL(dist_plans_.init(this))) {
SQL_PC_LOG(WARN, "failed to init dist plans", K(ret)); SQL_PC_LOG(WARN, "failed to init dist plans", K(ret));
} else { } else {
@ -1648,7 +1650,7 @@ int ObSqlPlanSet::get_plan_normal(ObPlanCacheCtx &pc_ctx,
int ObSqlPlanSet::try_get_local_plan(ObPlanCacheCtx &pc_ctx, int ObSqlPlanSet::try_get_local_plan(ObPlanCacheCtx &pc_ctx,
ObPhysicalPlan *&plan, ObPhysicalPlan *&plan,
bool &get_next) bool &get_next)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
@ -1678,7 +1680,7 @@ int ObSqlPlanSet::try_get_local_plan(ObPlanCacheCtx &pc_ctx,
} }
int ObSqlPlanSet::try_get_remote_plan(ObPlanCacheCtx &pc_ctx, int ObSqlPlanSet::try_get_remote_plan(ObPlanCacheCtx &pc_ctx,
ObPhysicalPlan *&plan, ObPhysicalPlan *&plan,
bool &get_next) bool &get_next)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;

View File

@ -250,7 +250,7 @@ public:
ObSqlPlanSet() ObSqlPlanSet()
: ObPlanSet(PST_SQL_CRSR), : ObPlanSet(PST_SQL_CRSR),
is_all_non_partition_(true), is_all_non_partition_(true),
table_locations_(), // use default behavior for memory release table_locations_(alloc_),
array_binding_plan_(), array_binding_plan_(),
local_plan_(NULL), local_plan_(NULL),
remote_plan_(NULL), remote_plan_(NULL),
@ -262,7 +262,6 @@ public:
is_contain_virtual_table_(false), is_contain_virtual_table_(false),
enable_inner_part_parallel_exec_(false) enable_inner_part_parallel_exec_(false)
{ {
table_locations_.set_attr(ObMemAttr(OB_SERVER_TENANT_ID, "TableLocations"));
} }
virtual ~ObSqlPlanSet() {} virtual ~ObSqlPlanSet() {}
@ -357,7 +356,7 @@ private:
bool is_local_plan_opt_allowed(int last_retry_err); bool is_local_plan_opt_allowed(int last_retry_err);
private: private:
bool is_all_non_partition_; //判断该plan对应的表是否均为非分区表 bool is_all_non_partition_; //判断该plan对应的表是否均为非分区表
common::ObSEArray<ObTableLocation, 1> table_locations_; TableLocationFixedArray table_locations_;
//used for array binding, only local plan //used for array binding, only local plan
ObPhysicalPlan *array_binding_plan_; ObPhysicalPlan *array_binding_plan_;
ObPhysicalPlan *local_plan_; ObPhysicalPlan *local_plan_;