add a new config, which can force malloc even if tenant not exist in observer

This commit is contained in:
tushicheng
2023-09-13 03:10:27 +00:00
committed by ob-robot
parent 914713a8d9
commit 1910d3de2b
8 changed files with 37 additions and 37 deletions

View File

@ -619,6 +619,8 @@ extern bool is_ob_mem_mgr_path();
#define FORCE_EXPLICT_500_MALLOC() \ #define FORCE_EXPLICT_500_MALLOC() \
OB_UNLIKELY(oceanbase::lib::ObMallocAllocator::get_instance()->force_explict_500_malloc_) OB_UNLIKELY(oceanbase::lib::ObMallocAllocator::get_instance()->force_explict_500_malloc_)
#define FORCE_MALLOC_FOR_ABSENT_TENANT() \
OB_UNLIKELY(oceanbase::lib::ObMallocAllocator::get_instance()->force_malloc_for_absent_tenant_)
} // end of namespace lib } // end of namespace lib
} // end of namespace oceanbase } // end of namespace oceanbase

View File

@ -153,6 +153,15 @@ void *ObMallocAllocator::alloc(const int64_t size, const oceanbase::lib::ObMemAt
ptr = allocator->alloc(size, inner_attr); ptr = allocator->alloc(size, inner_attr);
} }
} }
} else if (OB_ENTRY_NOT_EXIST == ret && FORCE_MALLOC_FOR_ABSENT_TENANT()) {
ret = OB_SUCCESS;
LOG_INFO("force malloc when tenant allocator does not exist");
inner_attr.tenant_id_ = OB_SERVER_TENANT_ID;
allocator = get_tenant_ctx_allocator(inner_attr.tenant_id_, inner_attr.ctx_id_);
if (OB_ISNULL(allocator)) {
} else {
ptr = allocator->alloc(size, inner_attr);
}
} }
return ptr; return ptr;

View File

@ -161,6 +161,7 @@ public:
public: public:
bool force_explict_500_malloc_ = false; bool force_explict_500_malloc_ = false;
bool pl_leaked_times_ = 0; bool pl_leaked_times_ = 0;
bool force_malloc_for_absent_tenant_ = false;
private: private:
DISALLOW_COPY_AND_ASSIGN(ObMallocAllocator); DISALLOW_COPY_AND_ASSIGN(ObMallocAllocator);
class BucketLock class BucketLock

View File

@ -30,26 +30,20 @@ void *ObAllocator::alloc(const int64_t size, const ObMemAttr &attr)
ret = init(); ret = init();
} }
if (OB_SUCC(ret)) { if (OB_SUCC(ret)) {
if (do_not_use_me_) {
ObMemAttr inner_attr = nattr_;
if (attr.label_.is_valid()) {
inner_attr.label_ = attr.label_;
}
auto ta = lib::ObMallocAllocator::get_instance()->get_tenant_ctx_allocator(inner_attr.tenant_id_,
inner_attr.ctx_id_);
if (ta != NULL) {
ptr = ObTenantCtxAllocator::common_alloc(size, inner_attr, *(ta.ref_allocator()), nos_);
}
}
if (OB_LIKELY(!ptr)) {
ObMemAttr inner_attr = attr_; ObMemAttr inner_attr = attr_;
if (attr.label_.is_valid()) { if (attr.label_.is_valid()) {
inner_attr.label_ = attr.label_; inner_attr.label_ = attr.label_;
} }
auto ta = lib::ObMallocAllocator::get_instance()->get_tenant_ctx_allocator(inner_attr.tenant_id_, auto ta = lib::ObMallocAllocator::get_instance()->get_tenant_ctx_allocator(inner_attr.tenant_id_,
inner_attr.ctx_id_); inner_attr.ctx_id_);
if (ta != NULL) { if (OB_LIKELY(NULL != ta)) {
ptr = ObTenantCtxAllocator::common_alloc(size, inner_attr, *(ta.ref_allocator()), os_); ptr = ObTenantCtxAllocator::common_alloc(size, inner_attr, *(ta.ref_allocator()), os_);
} else if (FORCE_MALLOC_FOR_ABSENT_TENANT()) {
inner_attr.tenant_id_ = OB_SERVER_TENANT_ID;
ta = lib::ObMallocAllocator::get_instance()->get_tenant_ctx_allocator(inner_attr.tenant_id_,
inner_attr.ctx_id_);
if (NULL != ta) {
ptr = ObTenantCtxAllocator::common_alloc(size, inner_attr, *(ta.ref_allocator()), nos_);
} }
} }
} }

View File

@ -67,9 +67,7 @@ private:
void reset() override { os_.reset(); } void reset() override { os_.reset(); }
private: private:
__MemoryContext__ *mem_context_; __MemoryContext__ *mem_context_;
bool do_not_use_me_;
ObMemAttr attr_; ObMemAttr attr_;
ObMemAttr nattr_;
const bool use_pm_; const bool use_pm_;
void *pm_; void *pm_;
lib::ISetLocker *locker_; lib::ISetLocker *locker_;
@ -123,7 +121,6 @@ public:
inline ObAllocator::ObAllocator(__MemoryContext__ *mem_context, const ObMemAttr &attr, const bool use_pm, inline ObAllocator::ObAllocator(__MemoryContext__ *mem_context, const ObMemAttr &attr, const bool use_pm,
const uint32_t ablock_size) const uint32_t ablock_size)
: mem_context_(mem_context), : mem_context_(mem_context),
do_not_use_me_(false),
attr_(attr), attr_(attr),
use_pm_(use_pm), use_pm_(use_pm),
pm_(nullptr), pm_(nullptr),
@ -134,16 +131,6 @@ inline ObAllocator::ObAllocator(__MemoryContext__ *mem_context, const ObMemAttr
nos_(mem_context_, ablock_size), nos_(mem_context_, ablock_size),
is_inited_(false) is_inited_(false)
{ {
nattr_ = attr_;
do_not_use_me_ = false;
if (FORCE_EXPLICT_500_MALLOC()) {
do_not_use_me_ = OB_SERVER_TENANT_ID == attr.tenant_id_ && !attr.use_500() &&
ob_thread_tenant_id() != OB_SERVER_TENANT_ID;
if (do_not_use_me_) {
nattr_.tenant_id_ = ob_thread_tenant_id();
nattr_.ctx_id_ = ObCtxIds::DO_NOT_USE_ME;
}
}
} }
inline int ObAllocator::init() inline int ObAllocator::init()
@ -165,13 +152,12 @@ inline int ObAllocator::init()
blk_mgr_.set_tenant_id(attr_.tenant_id_); blk_mgr_.set_tenant_id(attr_.tenant_id_);
blk_mgr_.set_ctx_id(attr_.ctx_id_); blk_mgr_.set_ctx_id(attr_.ctx_id_);
blk_mgr = &blk_mgr_; blk_mgr = &blk_mgr_;
if (do_not_use_me_) {
nblk_mgr_.set_tenant_id(nattr_.tenant_id_);
nblk_mgr_.set_ctx_id(nattr_.ctx_id_);
nblk_mgr = &nblk_mgr_;
}
} }
if (OB_SUCC(ret)) { if (OB_SUCC(ret)) {
nblk_mgr_.set_tenant_id(OB_SERVER_TENANT_ID);
nblk_mgr_.set_ctx_id(attr_.ctx_id_);
nblk_mgr = &nblk_mgr_;
os_.set_block_mgr(blk_mgr); os_.set_block_mgr(blk_mgr);
os_.set_locker(locker_); os_.set_locker(locker_);
nos_.set_block_mgr(nblk_mgr); nos_.set_block_mgr(nblk_mgr);

View File

@ -318,6 +318,10 @@ int ObServerReloadConfig::operator()()
{ {
common::g_enable_backtrace = GCONF._enable_backtrace_function; common::g_enable_backtrace = GCONF._enable_backtrace_function;
} }
{
ObMallocAllocator::get_instance()->force_malloc_for_absent_tenant_ = GCONF._force_malloc_for_absent_tenant;
}
return real_ret; return real_ret;
} }

View File

@ -1589,6 +1589,9 @@ DEF_BOOL(_enable_system_tenant_memory_limit, OB_CLUSTER_PARAMETER, "True",
"specifies whether allowed to limit the memory of tenant 500", "specifies whether allowed to limit the memory of tenant 500",
ObParameterAttr(Section::OBSERVER, Source::DEFAULT, EditLevel::DYNAMIC_EFFECTIVE)); ObParameterAttr(Section::OBSERVER, Source::DEFAULT, EditLevel::DYNAMIC_EFFECTIVE));
#endif #endif
DEF_BOOL(_force_malloc_for_absent_tenant, OB_CLUSTER_PARAMETER, "False",
"force malloc even if tenant does not exist in observer",
ObParameterAttr(Section::OBSERVER, Source::DEFAULT, EditLevel::DYNAMIC_EFFECTIVE));
ERRSIM_DEF_TIME(errsim_transfer_backfill_error_time, OB_TENANT_PARAMETER, "0", "[0s,1h]", ERRSIM_DEF_TIME(errsim_transfer_backfill_error_time, OB_TENANT_PARAMETER, "0", "[0s,1h]",
"the duration of the error happened to transfer backfill. " "the duration of the error happened to transfer backfill. "
"Range: [0s, 1h] in duration", "Range: [0s, 1h] in duration",

View File

@ -295,6 +295,7 @@ _follower_snapshot_read_retry_duration
_force_explict_500_malloc _force_explict_500_malloc
_force_hash_groupby_dump _force_hash_groupby_dump
_force_hash_join_spill _force_hash_join_spill
_force_malloc_for_absent_tenant
_force_skip_encoding_partition_id _force_skip_encoding_partition_id
_hash_area_size _hash_area_size
_hash_join_enabled _hash_join_enabled