diff --git a/deps/oblib/src/lib/alloc/memory_dump.cpp b/deps/oblib/src/lib/alloc/memory_dump.cpp index 257c683bd..ef9ffaad9 100644 --- a/deps/oblib/src/lib/alloc/memory_dump.cpp +++ b/deps/oblib/src/lib/alloc/memory_dump.cpp @@ -101,8 +101,8 @@ int ObMemoryDump::init() } else if (OB_FAIL(queue_.init(TASK_NUM, "memdumpqueue"))) { LOG_WARN("task queue init failed", K(ret)); } else { - MemoryContext* context = nullptr; - int ret = ROOT_CONTEXT.CREATE_CONTEXT(context, ContextParam().set_label("MemDumpContext")); + MemoryContext context = nullptr; + int ret = ROOT_CONTEXT->CREATE_CONTEXT(context, ContextParam().set_label("MemDumpContext")); PreAllocMemory* pre_mem = nullptr; if (OB_FAIL(ret)) { LOG_WARN("create context failed", K(ret)); @@ -546,7 +546,7 @@ void ObMemoryDump::handle(void* task) print_pos += m_task->to_string(print_buf_ + print_pos, PRINT_BUF_LEN - print_pos); ret = databuff_printf(print_buf_, PRINT_BUF_LEN, print_pos, "\n"); if (DUMP_CONTEXT == m_task->type_) { - MemoryContext* context = reinterpret_cast(m_task->p_context_); + __MemoryContext__ *context = reinterpret_cast<__MemoryContext__*>(m_task->p_context_); auto func = [&] { const char* str = to_cstring(*context); ::write(fd, str, strlen(str)); diff --git a/deps/oblib/src/lib/alloc/memory_dump.h b/deps/oblib/src/lib/alloc/memory_dump.h index c406ecc51..a1c7b665e 100644 --- a/deps/oblib/src/lib/alloc/memory_dump.h +++ b/deps/oblib/src/lib/alloc/memory_dump.h @@ -180,7 +180,7 @@ private: AChunk** chunks_; }; uint64_t* tenant_ids_; - lib::MemoryContext* dump_context_; + lib::MemoryContext dump_context_; LabelMap lmap_; common::ObLatch iter_lock_; Stat* r_stat_; diff --git a/deps/oblib/src/lib/alloc/object_set.cpp b/deps/oblib/src/lib/alloc/object_set.cpp index 3ec5ea553..5f29e592b 100644 --- a/deps/oblib/src/lib/alloc/object_set.cpp +++ b/deps/oblib/src/lib/alloc/object_set.cpp @@ -33,7 +33,7 @@ void __attribute__((weak)) has_unfree_callback(char* info) _OB_LOG(ERROR, "HAS UNFREE PTR!!! %s", info); } -ObjectSet::ObjectSet(MemoryContext* mem_context, const uint32_t ablock_size) +ObjectSet::ObjectSet(__MemoryContext__* mem_context, const uint32_t ablock_size) : mem_context_(mem_context), locker_(nullptr), mod_set_(nullptr), diff --git a/deps/oblib/src/lib/alloc/object_set.h b/deps/oblib/src/lib/alloc/object_set.h index 809244d24..657f21db8 100644 --- a/deps/oblib/src/lib/alloc/object_set.h +++ b/deps/oblib/src/lib/alloc/object_set.h @@ -25,7 +25,7 @@ namespace common { class ObAllocator; } namespace lib { -class MemoryContext; +class __MemoryContext__; class ObTenantCtxAllocator; class IBlockMgr; class ISetLocker; @@ -40,7 +40,7 @@ class ObjectSet { typedef ABitSet BitMap; public: - ObjectSet(MemoryContext* mem_context = nullptr, const uint32_t ablock_size = INTACT_NORMAL_AOBJECT_SIZE); + ObjectSet(__MemoryContext__* mem_context = nullptr, const uint32_t ablock_size = INTACT_NORMAL_AOBJECT_SIZE); ~ObjectSet(); // main interfaces @@ -101,7 +101,7 @@ private: void do_free_dirty_list(); private: - MemoryContext* mem_context_; + __MemoryContext__* mem_context_; ISetLocker* locker_; common::ObLocalModSet* mod_set_; IBlockMgr* blk_mgr_; diff --git a/deps/oblib/src/lib/allocator/ob_allocator_v2.h b/deps/oblib/src/lib/allocator/ob_allocator_v2.h index eec6383c8..6d6888180 100644 --- a/deps/oblib/src/lib/allocator/ob_allocator_v2.h +++ b/deps/oblib/src/lib/allocator/ob_allocator_v2.h @@ -23,20 +23,20 @@ namespace oceanbase { namespace lib { -class MemoryContext; +class __MemoryContext__; } namespace common { using common::ObPageManager; using lib::AObject; -using lib::MemoryContext; +using lib::__MemoryContext__; using lib::ObjectSet; class ObAllocator : public ObIAllocator { - friend class lib::MemoryContext; + friend class lib::__MemoryContext__; friend class ObParallelAllocator; public: - ObAllocator(MemoryContext* mem_context, const ObMemAttr& attr = default_memattr, const bool use_pm = false, + ObAllocator(__MemoryContext__* mem_context, const ObMemAttr& attr = default_memattr, const bool use_pm = false, const uint32_t ablock_size = lib::INTACT_NORMAL_AOBJECT_SIZE); void* alloc(const int64_t size) override { @@ -71,7 +71,7 @@ private: } private: - MemoryContext* mem_context_; + __MemoryContext__* mem_context_; ObMemAttr attr_; const bool use_pm_; void* pm_; @@ -84,7 +84,7 @@ private: }; inline ObAllocator::ObAllocator( - MemoryContext* mem_context, const ObMemAttr& attr, const bool use_pm, const uint32_t ablock_size) + __MemoryContext__* mem_context, const ObMemAttr& attr, const bool use_pm, const uint32_t ablock_size) : mem_context_(mem_context), attr_(attr), use_pm_(use_pm), @@ -141,7 +141,7 @@ class ObParallelAllocator : public ObIAllocator { static const int N = 8; public: - ObParallelAllocator(ObAllocator& root_allocator, MemoryContext* mem_context, const ObMemAttr& attr = default_memattr, + ObParallelAllocator(ObAllocator& root_allocator, __MemoryContext__* mem_context, const ObMemAttr& attr = default_memattr, const int parallel = 4, const uint32_t ablock_size = lib::INTACT_NORMAL_AOBJECT_SIZE); virtual ~ObParallelAllocator(); void* alloc(const int64_t size) override @@ -162,7 +162,7 @@ private: private: ObAllocator& root_allocator_; - MemoryContext* mem_context_; + __MemoryContext__* mem_context_; ObMemAttr attr_; uint32_t ablock_size_; // buffer of sub_allocators_ @@ -176,7 +176,7 @@ private: lib::ObMutex mutex_; }; -inline ObParallelAllocator::ObParallelAllocator(ObAllocator& root_allocator, MemoryContext* mem_context, +inline ObParallelAllocator::ObParallelAllocator(ObAllocator& root_allocator, __MemoryContext__* mem_context, const ObMemAttr& attr, const int parallel, const uint32_t ablock_size) : root_allocator_(root_allocator), mem_context_(mem_context), diff --git a/deps/oblib/src/lib/container/ob_raw_se_array.h b/deps/oblib/src/lib/container/ob_raw_se_array.h index fc41a4d22..9f6a253b4 100644 --- a/deps/oblib/src/lib/container/ob_raw_se_array.h +++ b/deps/oblib/src/lib/container/ob_raw_se_array.h @@ -222,7 +222,7 @@ private: { if (OB_UNLIKELY(!has_alloc_)) { if (auto_free) { - mem_context_ = &CURRENT_CONTEXT; + mem_context_ = CURRENT_CONTEXT; block_allocator_ = BlockAllocatorT(mem_context_->get_allocator()); } has_alloc_ = true; @@ -253,7 +253,7 @@ private: int error_; BlockAllocatorT block_allocator_; bool has_alloc_; - lib::MemoryContext* mem_context_; + lib::MemoryContext mem_context_; }; template diff --git a/deps/oblib/src/lib/container/ob_se_array.h b/deps/oblib/src/lib/container/ob_se_array.h index 79a58ea96..4c03178b8 100644 --- a/deps/oblib/src/lib/container/ob_se_array.h +++ b/deps/oblib/src/lib/container/ob_se_array.h @@ -55,11 +55,11 @@ public: template static inline void init_block_allocator(lib::MemoryContext& mem_entity, BlockAllocatorT& block_allocator) { - block_allocator = BlockAllocatorT(mem_entity.get_allocator()); + block_allocator = BlockAllocatorT(mem_entity->get_allocator()); } static inline void init_block_allocator(lib::MemoryContext& mem_entity, ModulePageAllocator& block_allocator) { - block_allocator = ModulePageAllocator(mem_entity.get_allocator(), block_allocator.get_label()); + block_allocator = ModulePageAllocator(mem_entity->get_allocator(), block_allocator.get_label()); } // ObSEArrayImpl is a high performant array for OceanBase developers, @@ -310,8 +310,8 @@ private: { if (OB_UNLIKELY(!has_alloc_)) { if (auto_free) { - mem_context_ = &CURRENT_CONTEXT; - init_block_allocator(*mem_context_, block_allocator_); + mem_context_ = CURRENT_CONTEXT; + init_block_allocator(mem_context_, block_allocator_); } has_alloc_ = true; } else { @@ -342,7 +342,7 @@ private: int error_; BlockAllocatorT block_allocator_; bool has_alloc_; - lib::MemoryContext* mem_context_; + lib::MemoryContext mem_context_; }; template diff --git a/deps/oblib/src/lib/coro/co_routine.cpp b/deps/oblib/src/lib/coro/co_routine.cpp index b7e176258..ce8562788 100644 --- a/deps/oblib/src/lib/coro/co_routine.cpp +++ b/deps/oblib/src/lib/coro/co_routine.cpp @@ -126,7 +126,7 @@ void CoRoutine::__start(transfer_t from) routine.set_run_status(RunStatus::RUNNING); routine.at_create(); int ret = OB_SUCCESS; - MemoryContext** mem_context = GET_TSI0(MemoryContext*); + MemoryContext* mem_context = GET_TSI0(MemoryContext); // Thread has ensured the thread-local mem_context is created successfully assert(mem_context != nullptr && *mem_context != nullptr); WITH_CONTEXT(*mem_context) diff --git a/deps/oblib/src/lib/coro/thread.cpp b/deps/oblib/src/lib/coro/thread.cpp index cdf6146f0..487939ab1 100644 --- a/deps/oblib/src/lib/coro/thread.cpp +++ b/deps/oblib/src/lib/coro/thread.cpp @@ -205,16 +205,16 @@ void* Thread::__th_start(void* arg) !lib::is_mini_mode() ? ObPageManager::DEFAULT_CHUNK_CACHE_CNT : ObPageManager::MINI_MODE_CHUNK_CACHE_CNT; pm.set_max_chunk_cache_cnt(cache_cnt); ObPageManager::set_thread_local_instance(pm); - MemoryContext** mem_context = GET_TSI0(MemoryContext*); + MemoryContext* mem_context = GET_TSI0(MemoryContext); if (OB_ISNULL(mem_context)) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_ERROR("alloc mem_context failed", K(ret)); } else { - ret = ROOT_CONTEXT.CREATE_CONTEXT( + ret = ROOT_CONTEXT->CREATE_CONTEXT( *mem_context, ContextParam().set_properties(RETURN_MALLOC_DEFAULT).set_label("ThreadRoot")); if (OB_FAIL(ret)) { LOG_ERROR("create memory context failed", K(ret)); - } else if (OB_ISNULL(*mem_context)) { + } else if (OB_ISNULL(mem_context)) { ret = OB_ERR_UNEXPECTED; LOG_ERROR("null ptr", K(ret)); } else { diff --git a/deps/oblib/src/lib/rc/context.cpp b/deps/oblib/src/lib/rc/context.cpp index 76e93f67f..b424af79f 100644 --- a/deps/oblib/src/lib/rc/context.cpp +++ b/deps/oblib/src/lib/rc/context.cpp @@ -21,9 +21,10 @@ namespace oceanbase { namespace lib { RLOCAL(bool, ContextTLOptGuard::enable_tl_opt); -MemoryContext& MemoryContext::root() +int64_t __MemoryContext__::g_seq_id = 0; +__MemoryContext__ &__MemoryContext__::root() { - static MemoryContext* root = nullptr; + static __MemoryContext__ *root = nullptr; if (OB_UNLIKELY(nullptr == root)) { static lib::ObMutex mutex; lib::ObMutexGuard guard(mutex); @@ -33,8 +34,9 @@ MemoryContext& MemoryContext::root() .set_parallel(4) .set_mem_attr(OB_SERVER_TENANT_ID, ObModIds::OB_ROOT_CONTEXT, ObCtxIds::DEFAULT_CTX_ID); // ObMallocAllocator to design a non-destroy mode - const static int static_id = StaticInfos::get_instance().add(__FILENAME__, __LINE__, __FUNCTION__); - MemoryContext* tmp = new (std::nothrow) MemoryContext(false, DynamicInfo(), nullptr, param, static_id); + const static int static_id = + StaticInfos::get_instance().add(__FILENAME__, __LINE__, __FUNCTION__); + __MemoryContext__ *tmp = new (std::nothrow) __MemoryContext__(false, DynamicInfo(), nullptr, param, static_id); abort_unless(tmp != nullptr); int ret = tmp->init(); abort_unless(OB_SUCCESS == ret); @@ -44,5 +46,11 @@ MemoryContext& MemoryContext::root() return *root; } -} // end of namespace lib -} // end of namespace oceanbase +MemoryContext &MemoryContext::root() +{ + static MemoryContext root(&__MemoryContext__::root()); + return root; +} + +} // end of namespace lib +} // end of namespace oceanbase diff --git a/deps/oblib/src/lib/rc/context.h b/deps/oblib/src/lib/rc/context.h index 5dc37c5e3..796cd55c9 100644 --- a/deps/oblib/src/lib/rc/context.h +++ b/deps/oblib/src/lib/rc/context.h @@ -36,7 +36,7 @@ namespace lib { #define CURRENT_CONTEXT lib::Flow::current_ctx() #define ROOT_CONTEXT lib::MemoryContext::root() #define CREATE_CONTEXT(args...) CREATE_CONTEXT_(CONCAT(static_id, __COUNTER__), args) -#define DESTROY_CONTEXT(context) lib::MemoryContext::destory_context(context) +#define DESTROY_CONTEXT(context) lib::__MemoryContext__::destory_context(context) #define WITH_CONTEXT(context) WITH_CONTEXT_P(true, context) #define WITH_CONTEXT_P(condition, context) CONTEXT_P(condition, lib::ContextSource::WITH, context) #define CREATE_WITH_TEMP_CONTEXT(...) CREATE_WITH_TEMP_CONTEXT_P(true, __VA_ARGS__) @@ -55,17 +55,18 @@ namespace lib { const static int static_id = lib::StaticInfos::get_instance().add(__FILENAME__, __LINE__, __FUNCTION__); \ CONTEXT_P(condition, lib::ContextSource::CREATE, lib::DynamicInfo(), __VA_ARGS__, static_id) +using std::nullptr_t; using lib::ObMemAttr; using oceanbase::common::default_memattr; class Flow; -class MemoryContext; +class __MemoryContext__; enum class ContextSource { WITH, // The parameter is already the target Context, switch directly CREATE // Created by parameters }; class ContextTLOptGuard { - friend class MemoryContext; + friend class __MemoryContext__; static RLOCAL(bool, enable_tl_opt); public: @@ -176,8 +177,7 @@ public: }; class ContextParam { - friend class MemoryContext; - + friend class __MemoryContext__; public: ContextParam() : properties_(DEFAULT_PROPERTIES), @@ -276,38 +276,64 @@ struct DynamicInfo { int64_t create_time_; }; -class MemoryContext { - friend class TreeNode; - +class MemoryContext +{ + friend class __MemoryContext__; + constexpr static uint64_t MAGIC_CODE = 0xedde13244231dede; public: - MemoryContext( - const bool need_free, const DynamicInfo& di, MemoryContext* parent, ContextParam& param, const int static_id) - : need_free_(need_free), - tree_node_(parent != nullptr ? &parent->tree_node_ : nullptr, param.properties_ & ADD_CHILD_THREAD_SAFE), - di_(di), - param_(param), - properties_(param.properties_), - static_id_(static_id), - p_alloc_(nullptr), - p_arena_alloc_(nullptr), - p_safe_arena_alloc_(nullptr), - parallel_alloc_(nullptr), - freeable_alloc_(nullptr), - default_allocator_(nullptr) - {} - int get_static_id() const + MemoryContext(__MemoryContext__ *ref_context) { - return static_id_; + operator=(ref_context); } - const DynamicInfo& get_dynamic_info() const + MemoryContext() { - return di_; + operator=(nullptr); } - const StaticInfo& get_static_info() const + MemoryContext &operator=(__MemoryContext__ *ref_context); + __MemoryContext__* operator->() const + { return ref_context_; } + __MemoryContext__ *ref_context() const + { return ref_context_; } + bool check_magic_code() const { return MAGIC_CODE == magic_code_; } + static MemoryContext &root(); +private: + int64_t magic_code_; + int64_t seq_id_; + __MemoryContext__ *ref_context_; +}; + +class __MemoryContext__ +{ + friend class TreeNode; + friend class MemoryContext; + constexpr static uint64_t MAGIC_CODE = 0xfddf13244231dfdf; +public: + static int64_t g_seq_id; +public: + __MemoryContext__(const bool need_free, const DynamicInfo &di, __MemoryContext__ *parent, + ContextParam ¶m, const int static_id) + : magic_code_(-1), + seq_id_(-1), + need_free_(need_free), + tree_node_(parent != nullptr ? &parent->tree_node_ : nullptr, + param.properties_ & ADD_CHILD_THREAD_SAFE), + di_(di), + param_(param), + properties_(param.properties_), + static_id_(static_id), + p_alloc_(nullptr), + p_arena_alloc_(nullptr), + p_safe_arena_alloc_(nullptr), + parallel_alloc_(nullptr), + freeable_alloc_(nullptr), + default_allocator_(nullptr) { - return StaticInfos::get_instance().get(static_id_); } - void* allocf(const int64_t size, const ObMemAttr& attr = default_memattr) + int get_static_id() const { return static_id_; } + const DynamicInfo &get_dynamic_info() const { return di_; } + const StaticInfo &get_static_info() const { return StaticInfos::get_instance().get(static_id_); } + void *allocf(const int64_t size, + const ObMemAttr &attr=default_memattr) { return freeable_alloc_->alloc(size, attr); } @@ -375,14 +401,17 @@ public: OB_ASSERT(default_allocator_ != nullptr); return *default_allocator_; } - static MemoryContext& root(); - TO_STRING_KV(KP(this), "static_id", static_id_, "static_info", StaticInfos::get_instance().get(static_id_), - "dynamic info", di_, K(properties_), K(attr_)); - + static __MemoryContext__ &root(); + bool check_magic_code() const { return MAGIC_CODE == magic_code_; } + TO_STRING_KV(KP(this), + "static_id", static_id_, + "static_info", StaticInfos::get_instance().get(static_id_), + "dynamic info", di_, + K(properties_), K(attr_)); private: - static MemoryContext* node2context(TreeNode* node) + static __MemoryContext__ *node2context(TreeNode *node) { - return reinterpret_cast((char*)node - offsetof(MemoryContext, tree_node_)); + return reinterpret_cast<__MemoryContext__*>((char*)node - offsetof(__MemoryContext__, tree_node_)); } public: @@ -462,71 +491,96 @@ public: } tree_node_.deinit(); } - template - int create_context(MemoryContext*& context, const DynamicInfo& di, Args&&... args) + template + int create_context(MemoryContext &context, + const DynamicInfo &di, + Args && ... args) { int ret = common::OB_SUCCESS; - context = nullptr; + __MemoryContext__ *ref_context = nullptr; ObMemAttr attr; attr.label_ = "CreateContext"; - void* ptr = allocf(sizeof(MemoryContext), attr); + void *ptr = allocf(sizeof(__MemoryContext__), attr); if (OB_UNLIKELY(nullptr == ptr)) { ret = common::OB_ALLOCATE_MEMORY_FAILED; } else { - context = new (ptr) MemoryContext(/*need_free*/ true, di, this, args...); - if (OB_FAIL(context->init())) { + ref_context = new (ptr) __MemoryContext__(/*need_free*/true, di, this, args...); + if (OB_FAIL(ref_context->init())) { OB_LOG(WARN, "init failed", K(ret)); } } if (OB_FAIL(ret)) { - if (context != nullptr) { - context->deinit(); + if (ref_context != nullptr) { + ref_context->deinit(); } if (ptr != nullptr) { free(ptr); } + } else { + const int64_t seq_id = ATOMIC_AAF(&__MemoryContext__::g_seq_id, 1); + ref_context->magic_code_ = MAGIC_CODE; + ref_context->seq_id_ = seq_id; + context = ref_context; } - return ret; } - template - int create_context(MemoryContext& context, const DynamicInfo& di, Args&&... args) + template + int create_context(MemoryContext &context, + __MemoryContext__ &ref_context, + const DynamicInfo &di, + Args && ... args) { int ret = common::OB_SUCCESS; - new (&context) MemoryContext(/*need_free*/ false, di, this, args...); - if (OB_FAIL(context.init())) { + new (&ref_context) __MemoryContext__(/*need_free*/false, di, this, args...); + if (OB_FAIL(ref_context.init())) { OB_LOG(WARN, "init failed", K(ret)); } if (OB_FAIL(ret)) { - context.deinit(); + ref_context.deinit(); + } else { + const int64_t seq_id = ATOMIC_AAF(&__MemoryContext__::g_seq_id, 1); + ref_context.magic_code_ = MAGIC_CODE; + ref_context.seq_id_ = seq_id; + context = &ref_context; } return ret; } - static void destory_context(MemoryContext* mem_context) + static void destory_context(__MemoryContext__ *context) { - if (OB_LIKELY(mem_context != nullptr)) { - TreeNode* child_node = nullptr; - while ((child_node = mem_context->tree_node_.child_) != nullptr) { - MemoryContext* child = node2context(child_node); - destory_context(child); - } - const bool need_free = mem_context->need_free_; - TreeNode* parent_node = mem_context->tree_node_.parent_; - abort_unless(parent_node != nullptr); - mem_context->deinit(); - mem_context->tree_node_.~TreeNode(); - if (need_free) { - MemoryContext* parent = node2context(parent_node); - parent->free(mem_context); - } + abort_unless(context->check_magic_code()); + context->magic_code_ = 0; + context->seq_id_ = 0; + TreeNode *child_node = nullptr; + while ((child_node = context->tree_node_.child_) != nullptr) { + __MemoryContext__ *child = node2context(child_node); + destory_context(child); + } + const bool need_free = context->need_free_; + TreeNode *parent_node = context->tree_node_.parent_; + abort_unless(parent_node != nullptr); + context->deinit(); + context->tree_node_.~TreeNode(); + if (need_free) { + __MemoryContext__ *parent = node2context(parent_node); + parent->free(context); + } + } + static void destory_context(MemoryContext &context) + { + abort_unless(context.check_magic_code()); + auto *ref_context = context.ref_context_; + if (OB_LIKELY(ref_context != nullptr)) { + abort_unless(context.seq_id_ == ref_context->seq_id_); + destory_context(ref_context); } } - public: + int64_t magic_code_; + int64_t seq_id_; // Assignment is not in the constructor, record who assigns const bool need_free_; TreeNode tree_node_; @@ -557,7 +611,38 @@ public: ObIAllocator* default_allocator_; }; -class Flow final { +inline MemoryContext &MemoryContext::operator=(__MemoryContext__ *ref_context) +{ + ref_context_ = ref_context; + if (OB_LIKELY(ref_context != nullptr)) { + seq_id_ = ref_context->seq_id_; + } else { + seq_id_ = -1; + } + magic_code_ = MAGIC_CODE; + return *this; +} + +inline bool operator==(const MemoryContext &__a, nullptr_t) +{ return __a.ref_context() == nullptr; } + +inline bool operator==(nullptr_t, const MemoryContext &__b) +{ return nullptr == __b.ref_context(); } + +inline bool operator!=(const MemoryContext &__a, nullptr_t) +{ return __a.ref_context() != nullptr; } + +inline bool operator!=(nullptr_t, const MemoryContext &__b) +{ return nullptr != __b.ref_context(); } + +inline bool operator==(const MemoryContext &__a, const MemoryContext &__b) +{ return __a.ref_context() == __b.ref_context(); } + +inline bool operator!=(const MemoryContext &__a, const MemoryContext &__b) +{ return __a.ref_context() != __b.ref_context(); } + +class Flow final +{ public: Flow(MemoryContext& ref_context) : ref_context_(ref_context), prev_(nullptr), next_(nullptr), is_inited_(false) {} @@ -599,8 +684,8 @@ public: { Flow*& cur = g_flow(); if (OB_UNLIKELY(nullptr == cur)) { - static CoVar buf; - Flow* flow = new (&buf[0]) Flow(MemoryContext::root()); + static CoVar buf; + Flow *flow = new (&buf[0]) Flow(ROOT_CONTEXT); abort_unless(flow != nullptr); int ret = flow->init(); abort_unless(common::OB_SUCCESS == ret); @@ -626,25 +711,25 @@ private: } private: - MemoryContext& ref_context_; - Flow* prev_; - Flow* next_; + MemoryContext ref_context_; + Flow *prev_; + Flow *next_; bool is_inited_; }; inline void* ctxalf(const int64_t size, const ObMemAttr& attr = default_memattr) { - return CURRENT_CONTEXT.allocf(size, attr); + return CURRENT_CONTEXT->allocf(size, attr); } inline void* ctxalp(const int64_t size, const ObMemAttr& attr = default_memattr) { - return CURRENT_CONTEXT.allocp(size, attr); + return CURRENT_CONTEXT->allocp(size, attr); } inline void ctxfree(void* ptr) { - CURRENT_CONTEXT.free(ptr); + CURRENT_CONTEXT->free(ptr); } class _SBase { @@ -671,13 +756,14 @@ class _S {}; template <> class _S : public _SBase { public: - _S(const bool condition, MemoryContext* context) : _SBase(), flow_(nullptr) + _S(const bool condition, MemoryContext &context) + : _SBase(), flow_(nullptr) { int ret = common::OB_SUCCESS; if (OB_ISNULL(context)) { ret = common::OB_INVALID_ARGUMENT; } else if (condition) { - Flow* tmp_flow = new (buf_) Flow(*context); + Flow *tmp_flow = new (buf_) Flow(context); if (OB_FAIL(tmp_flow->init())) { } else { flow_ = tmp_flow; @@ -699,17 +785,17 @@ public: template <> class _S : public _SBase { public: - template - _S(const bool condition, Args&&... args) : _SBase(), context_(nullptr), flow_(nullptr) + template + _S(const bool condition, Args && ... args) + : _SBase(), flow_(nullptr) { int ret = common::OB_SUCCESS; if (OB_LIKELY(condition)) { - MemoryContext* tmp_context = reinterpret_cast(buf0_); - if (OB_FAIL(CURRENT_CONTEXT.create_context(*tmp_context, args...))) { + __MemoryContext__ *tmp_context = reinterpret_cast<__MemoryContext__*>(buf0_); + if (OB_FAIL(CURRENT_CONTEXT->create_context(context_, *tmp_context, args...))) { OB_LOG(WARN, "create context failed", K(ret)); } else { - context_ = tmp_context; - Flow* tmp_flow = new (buf1_) Flow(*context_); + Flow *tmp_flow = new (buf1_) Flow(context_); if (OB_FAIL(tmp_flow->init())) { } else { flow_ = tmp_flow; @@ -725,13 +811,13 @@ public: flow_->~Flow(); } if (context_ != nullptr) { - MemoryContext::destory_context(context_); + __MemoryContext__::destory_context(context_); } } - char buf0_[sizeof(MemoryContext)] __attribute__((aligned(16))); - char buf1_[sizeof(Flow)] __attribute__((aligned(16))); - MemoryContext* context_; - Flow* flow_; + char buf0_[sizeof(__MemoryContext__)] __attribute__ ((aligned (16))); + char buf1_[sizeof(Flow)] __attribute__ ((aligned (16))); + MemoryContext context_; + Flow *flow_; }; } // end of namespace lib diff --git a/deps/oblib/src/lib/worker.h b/deps/oblib/src/lib/worker.h index 2915a811e..9a48ab9be 100644 --- a/deps/oblib/src/lib/worker.h +++ b/deps/oblib/src/lib/worker.h @@ -135,7 +135,7 @@ inline bool Worker::has_req_flag() inline ObIAllocator& Worker::get_sql_arena_allocator() { - return CURRENT_CONTEXT.get_arena_allocator(); + return CURRENT_CONTEXT->get_arena_allocator(); } inline ObIAllocator& Worker::get_allocator() diff --git a/deps/oblib/unittest/lib/rc/test_context.cpp b/deps/oblib/unittest/lib/rc/test_context.cpp index 3e00f7461..a1c901e14 100644 --- a/deps/oblib/unittest/lib/rc/test_context.cpp +++ b/deps/oblib/unittest/lib/rc/test_context.cpp @@ -11,12 +11,12 @@ */ #define USING_LOG_PREFIX SHARE -#include #define private public #define protected public #include "lib/rc/context.h" #undef private #undef protected +#include #include "lib/alloc/ob_malloc_allocator.h" #include "lib/thread_local/ob_tsi_factory.h" #include "lib/alloc/memory_dump.h" @@ -46,10 +46,9 @@ TEST_F(TestContext, Basic) // There must be a Flow pointing to root on each thread auto& context = Flow::current_ctx(); auto& flow = Flow::current_flow(); - ASSERT_EQ(&MemoryContext::root(), &context); - ASSERT_TRUE(flow.prev_ == flow.next_ && flow.prev_ == nullptr); - ASSERT_TRUE(context.tree_node_.parent_ == context.tree_node_.child_ && - context.tree_node_.parent_ == context.tree_node_.next_ && context.tree_node_.parent_ == nullptr); + ASSERT_EQ(MemoryContext::root(), context); + ASSERT_TRUE(context->tree_node_.parent_ == context->tree_node_.child_ && + context->tree_node_.parent_ == context->tree_node_.next_ && context->tree_node_.parent_ == nullptr); uint64_t tenant_id = 1001; uint64_t ctx_id = ObCtxIds::WORK_AREA; ObMallocAllocator* ma = ObMallocAllocator::get_instance(); @@ -59,16 +58,16 @@ TEST_F(TestContext, Basic) ObPageManager::set_thread_local_instance(g_pm); g_pm.set_tenant_ctx(tenant_id, ctx_id); g_pm.set_max_chunk_cache_cnt(0); - MemoryContext& root = MemoryContext::root(); + MemoryContext root = MemoryContext::root(); ContextParam param; param.set_mem_attr(tenant_id, 0, ctx_id); ContextTLOptGuard guard(true); - param.properties_ = USE_TL_PAGE_OPTIONAL; - MemoryContext* mem_context = nullptr; - int ret = root.CREATE_CONTEXT(mem_context, param); + param.set_properties(USE_TL_PAGE_OPTIONAL); + MemoryContext mem_context = nullptr; + int ret = root->CREATE_CONTEXT(mem_context, param); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(&mem_context->get_allocator(), &mem_context->get_arena_allocator()); - int64_t used = g_pm.used_; + int64_t used = g_pm.get_used(); ASSERT_EQ(0, used); void* ptr = nullptr; WITH_CONTEXT(mem_context) @@ -76,7 +75,7 @@ TEST_F(TestContext, Basic) ptr = ctxalp(100); ASSERT_NE(ptr, nullptr); MEMSET(ptr, 0, 100); - ASSERT_GT(g_pm.used_, used); + ASSERT_GT(g_pm.get_used(), used); auto& P_MCTX = CURRENT_CONTEXT; auto& P_MFLOW = Flow::current_flow(); @@ -91,18 +90,16 @@ TEST_F(TestContext, Basic) CREATE_WITH_TEMP_CONTEXT_P(true, param) { ASSERT_NE(&CURRENT_CONTEXT, &P_MCTX); - ASSERT_EQ(Flow::current_flow().prev_, &P_MFLOW); - ASSERT_EQ(Flow::current_flow().next_, nullptr); - int64_t p_hold = P_MCTX.hold(); - int64_t hold = CURRENT_CONTEXT.hold(); + int64_t p_hold = P_MCTX->hold(); + int64_t hold = CURRENT_CONTEXT->hold(); for (int i = 0; i < 64; ++i) { ptr = ctxalp(100); ASSERT_NE(ptr, nullptr); } - ASSERT_GT(g_pm.used_, used); - ASSERT_EQ(p_hold, P_MCTX.hold()); - ASSERT_LT(hold, CURRENT_CONTEXT.hold()); - int64_t orig_pm_used = g_pm.used_; + ASSERT_GT(g_pm.get_used(), used); + ASSERT_EQ(p_hold, P_MCTX->hold()); + ASSERT_LT(hold, CURRENT_CONTEXT->hold()); + int64_t orig_pm_used = g_pm.get_used(); has_unfree = false; CREATE_WITH_TEMP_CONTEXT(param) { @@ -111,16 +108,16 @@ TEST_F(TestContext, Basic) ASSERT_NE(ptr, nullptr); ptr = ctxalf(100); ASSERT_NE(ptr, nullptr); - ObArenaAllocator& arena_alloc = CURRENT_CONTEXT.get_arena_allocator(); + ObArenaAllocator& arena_alloc = CURRENT_CONTEXT->get_arena_allocator(); ptr = arena_alloc.alloc(1024); ASSERT_NE(ptr, nullptr); - ObIAllocator& alloc = CURRENT_CONTEXT.get_malloc_allocator(); - int64_t ori_used = CURRENT_CONTEXT.used(); + ObIAllocator& alloc = CURRENT_CONTEXT->get_malloc_allocator(); + int64_t ori_used = CURRENT_CONTEXT->used(); ptr = alloc.alloc(1024); ASSERT_NE(ptr, nullptr); - ASSERT_GT(CURRENT_CONTEXT.used(), ori_used); + ASSERT_GT(CURRENT_CONTEXT->used(), ori_used); alloc.free(ptr); - ASSERT_EQ(CURRENT_CONTEXT.used(), ori_used); + ASSERT_EQ(CURRENT_CONTEXT->used(), ori_used); } } else @@ -128,7 +125,7 @@ TEST_F(TestContext, Basic) ASSERT_TRUE(false); } ASSERT_TRUE(has_unfree); - ASSERT_EQ(orig_pm_used, g_pm.used_); + ASSERT_EQ(orig_pm_used, g_pm.get_used()); CREATE_WITH_TEMP_CONTEXT(param) { { @@ -140,10 +137,10 @@ TEST_F(TestContext, Basic) ctxfree(ptr); } int sub_cnt = 8; - MemoryContext* subs[sub_cnt]; + MemoryContext subs[sub_cnt]; for (int i = 0; i < sub_cnt; ++i) { - param.properties_ = USE_TL_PAGE_OPTIONAL | RETURN_MALLOC_DEFAULT; - ret = CURRENT_CONTEXT.CREATE_CONTEXT(subs[i], param); + param.set_properties(USE_TL_PAGE_OPTIONAL | RETURN_MALLOC_DEFAULT); + ret = CURRENT_CONTEXT->CREATE_CONTEXT(subs[i], param); ASSERT_EQ(OB_SUCCESS, ret); ASSERT_EQ(&subs[i]->get_allocator(), &subs[i]->get_malloc_allocator()); ptr = subs[i]->allocp(100); @@ -152,10 +149,10 @@ TEST_F(TestContext, Basic) ASSERT_NE(ptr, nullptr); WITH_CONTEXT(subs[i]) { - ASSERT_EQ(subs[i], &CURRENT_CONTEXT); + ASSERT_EQ(subs[i], CURRENT_CONTEXT); ptr = ctxalp(100); ASSERT_NE(ptr, nullptr); - ptr = CURRENT_CONTEXT.get_arena_allocator().alloc(100); + ptr = CURRENT_CONTEXT->get_arena_allocator().alloc(100); ASSERT_NE(ptr, nullptr); } else @@ -163,17 +160,17 @@ TEST_F(TestContext, Basic) ASSERT_TRUE(false); } } - ASSERT_GT(g_pm.used_, orig_pm_used); - int64_t pm_used_before = g_pm.used_; + ASSERT_GT(g_pm.get_used(), orig_pm_used); + int64_t pm_used_before = g_pm.get_used(); for (int i = 0; i < sub_cnt / 2; ++i) { DESTROY_CONTEXT(subs[i]); - ASSERT_LT(g_pm.used_, pm_used_before); - pm_used_before = g_pm.used_; + ASSERT_LT(g_pm.get_used(), pm_used_before); + pm_used_before = g_pm.get_used(); } - ASSERT_GT(g_pm.used_, orig_pm_used); + ASSERT_GT(g_pm.get_used(), orig_pm_used); // check child num int child_cnt = 0; - for (auto cur = CURRENT_CONTEXT.tree_node_.child_; cur; cur = cur->next_, child_cnt++) + for (auto cur = CURRENT_CONTEXT->tree_node_.child_; cur; cur = cur->next_, child_cnt++) ; ASSERT_EQ(child_cnt, sub_cnt / 2); } @@ -181,7 +178,7 @@ TEST_F(TestContext, Basic) { ASSERT_TRUE(false); } - ASSERT_EQ(g_pm.used_, orig_pm_used); + ASSERT_EQ(g_pm.get_used(), orig_pm_used); } else { @@ -192,9 +189,9 @@ TEST_F(TestContext, Basic) { ASSERT_TRUE(false); } - ASSERT_GT(g_pm.used_, used); + ASSERT_GT(g_pm.get_used(), used); DESTROY_CONTEXT(mem_context); - ASSERT_EQ(g_pm.used_, used); + ASSERT_EQ(g_pm.get_used(), used); { get_mem_leak_checker().init(); @@ -222,7 +219,6 @@ TEST_F(TestContext, Basic) // test rate reset_mem_leak_checker_label("test2"); - reset_mem_leak_checker_rate(10); int i = 20; while (i--) { ob_malloc(100, "test2"); @@ -230,15 +226,14 @@ TEST_F(TestContext, Basic) get_mem_leak_checker().print(); usleep(1000 * 1000); - reset_mem_leak_checker_rate(20); i = 20; while (i--) { ob_malloc(100, "test2"); } get_mem_leak_checker().print(); - MemoryContext* ty = nullptr; - int ret = root.CREATE_CONTEXT(ty, param); + MemoryContext ty = nullptr; + int ret = root->CREATE_CONTEXT(ty, param); reset_mem_leak_checker_label("*@7"); ty->allocf(100, ObMemAttr(1, "test")); ty->allocf(103, ObMemAttr(1, 1)); diff --git a/src/observer/mysql/obmp_query.cpp b/src/observer/mysql/obmp_query.cpp index 30c96d66d..9c608c044 100644 --- a/src/observer/mysql/obmp_query.cpp +++ b/src/observer/mysql/obmp_query.cpp @@ -1076,7 +1076,7 @@ OB_INLINE int ObMPQuery::response_result(ObQueryExecCtx& query_ctx, bool force_s if (OB_LIKELY(NULL != result.get_physical_plan())) { if (need_execute_async && GET_MIN_CLUSTER_VERSION() >= CLUSTER_VERSION_2260) { ctx_.is_execute_async_ = true; - WITH_CONTEXT(&query_ctx.get_mem_context()) + WITH_CONTEXT(query_ctx.get_mem_context()) { if (OB_FAIL(register_callback_with_async(query_ctx))) { LOG_WARN("response result with async failed", K(ret)); diff --git a/src/observer/mysql/obmp_stmt_execute.cpp b/src/observer/mysql/obmp_stmt_execute.cpp index 830bb6342..357da1f1a 100644 --- a/src/observer/mysql/obmp_stmt_execute.cpp +++ b/src/observer/mysql/obmp_stmt_execute.cpp @@ -276,7 +276,7 @@ int ObMPStmtExecute::save_exception_for_arraybinding( exception.pos_ = pos; exception.error_code_ = static_cast(ob_errpkt_errno(error_code, lib::is_oracle_mode())); - ObIAllocator& alloc = CURRENT_CONTEXT.get_arena_allocator(); + ObIAllocator& alloc = CURRENT_CONTEXT->get_arena_allocator(); const ObWarningBuffer* wb = common::ob_get_tsi_warning_buffer(); if (OB_LIKELY(NULL != wb) && wb->get_err_code() == error_code) { @@ -341,7 +341,7 @@ int ObMPStmtExecute::before_process() ret = OB_INVALID_ARGUMENT; LOG_ERROR("invalid request", K(ret), K_(*req)); } else { - ObIAllocator& alloc = CURRENT_CONTEXT.get_arena_allocator(); + ObIAllocator& alloc = CURRENT_CONTEXT->get_arena_allocator(); if (OB_ISNULL(params_ = static_cast(alloc.alloc(sizeof(ParamStore))))) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("failed to allocate memory", K(ret)); diff --git a/src/observer/ob_inner_sql_result.cpp b/src/observer/ob_inner_sql_result.cpp index 35b363164..c3020a4b8 100644 --- a/src/observer/ob_inner_sql_result.cpp +++ b/src/observer/ob_inner_sql_result.cpp @@ -67,7 +67,7 @@ int ObInnerSQLResult::init() .set_properties(lib::USE_TL_PAGE_OPTIONAL) .set_page_size(OB_MALLOC_MIDDLE_BLOCK_SIZE) .set_ablock_size(lib::INTACT_MIDDLE_AOBJECT_SIZE); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mem_context_, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_context_, param))) { LOG_WARN("create memory entity failed", K(ret)); } else { result_set_ = new (buf_) ObResultSet(session_, mem_context_->get_arena_allocator()); diff --git a/src/observer/ob_inner_sql_result.h b/src/observer/ob_inner_sql_result.h index f288ef2b9..b24dd1c20 100644 --- a/src/observer/ob_inner_sql_result.h +++ b/src/observer/ob_inner_sql_result.h @@ -179,7 +179,7 @@ private: private: class MemEntifyDestroyGuard { public: - MemEntifyDestroyGuard(lib::MemoryContext*& entity) : ref_(entity) + MemEntifyDestroyGuard(lib::MemoryContext& entity) : ref_(entity) {} ~MemEntifyDestroyGuard() { @@ -190,7 +190,7 @@ private: } private: - lib::MemoryContext*& ref_; + lib::MemoryContext& ref_; }; typedef common::hash::ObHashMap ColumnMap; @@ -198,7 +198,7 @@ private: mutable bool column_indexed_; mutable ColumnMap column_map_; - lib::MemoryContext* mem_context_; + lib::MemoryContext mem_context_; // Memory of memory entity may referenced by sql_ctx_, use the guard to make // sure memory entity destroyed after sql_ctx_ destructed. MemEntifyDestroyGuard mem_context_destroy_guard_; diff --git a/src/observer/omt/ob_th_worker.cpp b/src/observer/omt/ob_th_worker.cpp index e63dc7373..f9d6c09ab 100644 --- a/src/observer/omt/ob_th_worker.cpp +++ b/src/observer/omt/ob_th_worker.cpp @@ -403,7 +403,7 @@ void ObThWorker::worker(int64_t& tenant_id, int64_t& req_recv_timestamp, int32_t public: AllocatorGuard(ObIAllocator** allocator) : allocator_(allocator) { - *allocator_ = &CURRENT_CONTEXT.get_arena_allocator(); + *allocator_ = &CURRENT_CONTEXT->get_arena_allocator(); } ~AllocatorGuard() { diff --git a/src/share/rc/ob_context.h b/src/share/rc/ob_context.h index 2857e9c0b..d59120c31 100644 --- a/src/share/rc/ob_context.h +++ b/src/share/rc/ob_context.h @@ -295,7 +295,7 @@ inline int create_entity(T_Entity*& entity, Args&&... args) lib::ObMemAttr attr; attr.label_ = "CreateEntity"; - void* ptr = ROOT_CONTEXT.allocf(sizeof(T_Entity), attr); + void* ptr = ROOT_CONTEXT->allocf(sizeof(T_Entity), attr); if (OB_ISNULL(ptr)) { ret = common::OB_ALLOCATE_MEMORY_FAILED; } else { @@ -331,7 +331,7 @@ inline void destroy_entity(T_Entity* entity) entity->deinit(); entity->~T_Entity(); if (need_free) { - ROOT_CONTEXT.free(entity); + ROOT_CONTEXT->free(entity); } } } diff --git a/src/share/schema/ob_schema_cache.cpp b/src/share/schema/ob_schema_cache.cpp index a89ba83cf..4e1f639a2 100644 --- a/src/share/schema/ob_schema_cache.cpp +++ b/src/share/schema/ob_schema_cache.cpp @@ -229,7 +229,7 @@ int ObSchemaCache::init() .set_properties(lib::ALLOC_THREAD_SAFE) .set_ablock_size(lib::INTACT_MIDDLE_AOBJECT_SIZE) .set_parallel(1); - if (OB_FAIL(ROOT_CONTEXT.CREATE_CONTEXT(mem_context_, param))) { + if (OB_FAIL(ROOT_CONTEXT->CREATE_CONTEXT(mem_context_, param))) { SQL_ENG_LOG(WARN, "create memory entity failed"); } else if (OB_ISNULL(mem_context_)) { ret = OB_ERR_UNEXPECTED; diff --git a/src/share/schema/ob_schema_cache.h b/src/share/schema/ob_schema_cache.h index af43a493e..5d2d5c3c5 100644 --- a/src/share/schema/ob_schema_cache.h +++ b/src/share/schema/ob_schema_cache.h @@ -91,7 +91,7 @@ private: NoSwapCache; typedef common::ObKVCache KVCache; - lib::MemoryContext* mem_context_; + lib::MemoryContext mem_context_; NoSwapCache sys_cache_; KVCache cache_; bool is_inited_; diff --git a/src/sql/engine/aggregate/ob_hash_distinct.cpp b/src/sql/engine/aggregate/ob_hash_distinct.cpp index 58d3a6544..4e30cb89c 100644 --- a/src/sql/engine/aggregate/ob_hash_distinct.cpp +++ b/src/sql/engine/aggregate/ob_hash_distinct.cpp @@ -934,7 +934,7 @@ int ObHashDistinct::ObHashDistinctCtx::assign_sub_ctx( ObModIds::OB_SQL_HASH_DIST, ObCtxIds::WORK_AREA) .set_properties(lib::USE_TL_PAGE_OPTIONAL); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mem_context_, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_context_, param))) { LOG_WARN("fail to create entity", K(ret)); } else if (OB_ISNULL(mem_context_)) { ret = OB_ERR_UNEXPECTED; @@ -1022,11 +1022,11 @@ int ObHashDistinct::init_op_ctx(ObExecContext& ctx) const } else if (OB_FAIL(init_cur_row(*op_ctx, need_copy_row_for_compute()))) { LOG_WARN("init current row failed", K(ret)); } else { - lib::MemoryContext* mem_context = nullptr; + lib::MemoryContext mem_context = nullptr; lib::ContextParam param; param.set_mem_attr(ctx.get_my_session()->get_effective_tenant_id(), ObModIds::OB_SQL_HASH_DIST, ObCtxIds::WORK_AREA) .set_properties(lib::USE_TL_PAGE_OPTIONAL); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mem_context, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_context, param))) { LOG_WARN("fail to create entity", K(ret)); } else if (OB_ISNULL(mem_context)) { ret = OB_ERR_UNEXPECTED; diff --git a/src/sql/engine/aggregate/ob_hash_distinct.h b/src/sql/engine/aggregate/ob_hash_distinct.h index a950ad1dc..bb22b2565 100644 --- a/src/sql/engine/aggregate/ob_hash_distinct.h +++ b/src/sql/engine/aggregate/ob_hash_distinct.h @@ -69,7 +69,7 @@ public: cur_ = 0; } TO_STRING_KV(K_(nbuckets), K_(buf_cnt), K_(cur)); - lib::MemoryContext* mem_context_; + lib::MemoryContext mem_context_; using RowArray = common::ObSegmentArray; RowArray buckets_; int64_t nbuckets_; @@ -174,7 +174,7 @@ public: // bool it_in_mem_; //iterate rows in mem HashTable* hash_tab_; ObChunkRowStore* ha_row_store_; - lib::MemoryContext* mem_context_ = nullptr; + lib::MemoryContext mem_context_ = nullptr; bool ha_is_full_; bool bkt_created_; bool child_finished_; diff --git a/src/sql/engine/aggregate/ob_hash_groupby.cpp b/src/sql/engine/aggregate/ob_hash_groupby.cpp index c44ba6163..186e9506f 100644 --- a/src/sql/engine/aggregate/ob_hash_groupby.cpp +++ b/src/sql/engine/aggregate/ob_hash_groupby.cpp @@ -76,7 +76,7 @@ public: param.set_mem_attr(exec_ctx_.get_my_session()->get_effective_tenant_id(), ObModIds::OB_HASH_NODE_GROUP_ROWS, ObCtxIds::WORK_AREA); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mem_context_, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_context_, param))) { LOG_WARN("memory entity create failed", K(ret)); } } @@ -147,7 +147,7 @@ private: int64_t group_idx_; // memory allocator for group by partitions - lib::MemoryContext* mem_context_; + lib::MemoryContext mem_context_; ObDList all_parts_; @@ -566,7 +566,6 @@ int64_t ObHashGroupBy::detect_part_cnt(const int64_t rows, ObHashGroupByCtx& gby K(gby_ctx.get_data_hold_size()), K(gby_ctx.get_part_hold_size()), K(rows), - K(gby_ctx.mem_context_), K(availble_mem_size), K(est_dump_size)); return part_cnt; diff --git a/src/sql/engine/aggregate/ob_hash_groupby_op.cpp b/src/sql/engine/aggregate/ob_hash_groupby_op.cpp index 6a858fe36..341ef0b27 100644 --- a/src/sql/engine/aggregate/ob_hash_groupby_op.cpp +++ b/src/sql/engine/aggregate/ob_hash_groupby_op.cpp @@ -138,7 +138,7 @@ int ObHashGroupByOp::init_mem_context() lib::ContextParam param; param.set_mem_attr( ctx_.get_my_session()->get_effective_tenant_id(), ObModIds::OB_HASH_NODE_GROUP_ROWS, ObCtxIds::WORK_AREA); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mem_context_, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_context_, param))) { LOG_WARN("memory entity create failed", K(ret)); } } @@ -519,7 +519,6 @@ int64_t ObHashGroupByOp::detect_part_cnt(const int64_t rows) const K(get_aggr_hold_size()), K(get_dump_part_hold_size()), K(rows), - K(mem_context_), K(availble_mem_size), K(est_dump_size)); return part_cnt; diff --git a/src/sql/engine/aggregate/ob_hash_groupby_op.h b/src/sql/engine/aggregate/ob_hash_groupby_op.h index db3460305..e513f0586 100644 --- a/src/sql/engine/aggregate/ob_hash_groupby_op.h +++ b/src/sql/engine/aggregate/ob_hash_groupby_op.h @@ -179,7 +179,7 @@ private: int64_t curr_group_id_; // memory allocator for group by partitions - lib::MemoryContext* mem_context_; + lib::MemoryContext mem_context_; ObDList dumped_group_parts_; ObChunkDatumStore group_store_; diff --git a/src/sql/engine/basic/ob_hash_partitioning_infrastructure.h b/src/sql/engine/basic/ob_hash_partitioning_infrastructure.h index e1148e955..b16cf7e14 100644 --- a/src/sql/engine/basic/ob_hash_partitioning_infrastructure.h +++ b/src/sql/engine/basic/ob_hash_partitioning_infrastructure.h @@ -489,7 +489,7 @@ private: static const int64_t MAX_BUCKET_NUM = 131072; // 1M = 131072 * 8 static const int64_t MAX_PART_LEVEL = 4; uint64_t tenant_id_; - lib::MemoryContext* mem_context_; + lib::MemoryContext mem_context_; common::ObIAllocator* alloc_; common::ObArenaAllocator* arena_alloc_; ObPartitionExtendHashTable hash_table_; @@ -544,7 +544,7 @@ inline int ObBasicHashPartInfrastructure::init_mem_contex lib::ContextParam param; param.set_properties(lib::USE_TL_PAGE_OPTIONAL) .set_mem_attr(tenant_id, common::ObModIds::OB_ARENA_HASH_JOIN, common::ObCtxIds::WORK_AREA); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mem_context_, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_context_, param))) { SQL_ENG_LOG(WARN, "create entity failed", K(ret)); } else if (OB_ISNULL(mem_context_)) { SQL_ENG_LOG(WARN, "mem entity is null", K(ret)); diff --git a/src/sql/engine/basic/ob_hash_partitioning_infrastructure_op.h b/src/sql/engine/basic/ob_hash_partitioning_infrastructure_op.h index 4c3ec1cf0..835c8af55 100644 --- a/src/sql/engine/basic/ob_hash_partitioning_infrastructure_op.h +++ b/src/sql/engine/basic/ob_hash_partitioning_infrastructure_op.h @@ -492,7 +492,7 @@ private: static const int64_t MAX_BUCKET_NUM = 131072; // 1M = 131072 * 8 static const int64_t MAX_PART_LEVEL = 4; uint64_t tenant_id_; - lib::MemoryContext* mem_context_; + lib::MemoryContext mem_context_; common::ObIAllocator* alloc_; common::ObArenaAllocator* arena_alloc_; ObHashPartitionExtendHashTable hash_table_; @@ -552,7 +552,7 @@ inline int ObHashPartInfrastructure::init_mem_context(uin param.set_properties(lib::USE_TL_PAGE_OPTIONAL) .set_mem_attr(tenant_id, common::ObModIds::OB_ARENA_HASH_JOIN, common::ObCtxIds::WORK_AREA) .set_ablock_size(lib::INTACT_MIDDLE_AOBJECT_SIZE); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mem_context_, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_context_, param))) { SQL_ENG_LOG(WARN, "create entity failed", K(ret)); } else if (OB_ISNULL(mem_context_)) { SQL_ENG_LOG(WARN, "mem entity is null", K(ret)); diff --git a/src/sql/engine/basic/ob_material.cpp b/src/sql/engine/basic/ob_material.cpp index e5a4f6b12..265ff6025 100644 --- a/src/sql/engine/basic/ob_material.cpp +++ b/src/sql/engine/basic/ob_material.cpp @@ -212,7 +212,7 @@ int ObMaterial::get_all_row_from_child(ObMaterialCtx& mat_ctx, ObSQLSessionInfo& lib::ContextParam param; param.set_mem_attr(tenant_id, ObModIds::OB_SQL_SORT_ROW, ObCtxIds::WORK_AREA) .set_properties(lib::USE_TL_PAGE_OPTIONAL); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mat_ctx.mem_context_, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mat_ctx.mem_context_, param))) { LOG_WARN("create entity failed", K(ret)); } else if (OB_ISNULL(mat_ctx.mem_context_)) { ret = OB_ERR_UNEXPECTED; diff --git a/src/sql/engine/basic/ob_material.h b/src/sql/engine/basic/ob_material.h index 086774049..a9a2f8f97 100644 --- a/src/sql/engine/basic/ob_material.h +++ b/src/sql/engine/basic/ob_material.h @@ -104,7 +104,7 @@ private: } private: - lib::MemoryContext* mem_context_; + lib::MemoryContext mem_context_; ObChunkRowStore row_store_; ObChunkRowStore::Iterator row_store_it_; int64_t row_id_; diff --git a/src/sql/engine/basic/ob_material_op.cpp b/src/sql/engine/basic/ob_material_op.cpp index 9ed4efb56..3a7333b7f 100644 --- a/src/sql/engine/basic/ob_material_op.cpp +++ b/src/sql/engine/basic/ob_material_op.cpp @@ -86,7 +86,7 @@ int ObMaterialOp::get_all_row_from_child(ObSQLSessionInfo& session) lib::ContextParam param; param.set_mem_attr(tenant_id, ObModIds::OB_SQL_SORT_ROW, ObCtxIds::WORK_AREA) .set_properties(lib::USE_TL_PAGE_OPTIONAL); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mem_context_, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_context_, param))) { LOG_WARN("create entity failed", K(ret)); } else if (OB_ISNULL(mem_context_)) { ret = OB_ERR_UNEXPECTED; diff --git a/src/sql/engine/basic/ob_material_op.h b/src/sql/engine/basic/ob_material_op.h index 1176e4fa1..019136c49 100644 --- a/src/sql/engine/basic/ob_material_op.h +++ b/src/sql/engine/basic/ob_material_op.h @@ -69,7 +69,7 @@ private: } private: - lib::MemoryContext* mem_context_; + lib::MemoryContext mem_context_; ObChunkDatumStore datum_store_; ObChunkDatumStore::Iterator datum_store_it_; friend class ObValues; diff --git a/src/sql/engine/connect_by/ob_nested_loop_connect_by.cpp b/src/sql/engine/connect_by/ob_nested_loop_connect_by.cpp index 6f00a48cd..591c6b87b 100644 --- a/src/sql/engine/connect_by/ob_nested_loop_connect_by.cpp +++ b/src/sql/engine/connect_by/ob_nested_loop_connect_by.cpp @@ -346,7 +346,7 @@ int ObConnectBy::inner_open(ObExecContext& exec_ctx) const } if (OB_FAIL(ret)) { - } else if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(join_ctx->mem_context_, param))) { + } else if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(join_ctx->mem_context_, param))) { LOG_WARN("create entity failed", K(ret)); } else if (OB_ISNULL(join_ctx->mem_context_)) { ret = OB_ERR_UNEXPECTED; diff --git a/src/sql/engine/connect_by/ob_nested_loop_connect_by.h b/src/sql/engine/connect_by/ob_nested_loop_connect_by.h index 55f3f96c7..68069d9ef 100644 --- a/src/sql/engine/connect_by/ob_nested_loop_connect_by.h +++ b/src/sql/engine/connect_by/ob_nested_loop_connect_by.h @@ -161,7 +161,7 @@ public: private: ObConnectByPump connect_by_pump_; - lib::MemoryContext* mem_context_; + lib::MemoryContext mem_context_; ObSqlWorkAreaProfile profile_; ObSqlMemMgrProcessor sql_mem_processor_; }; diff --git a/src/sql/engine/dml/ob_table_insert_op.cpp b/src/sql/engine/dml/ob_table_insert_op.cpp index ed12fdfb0..cb734143c 100644 --- a/src/sql/engine/dml/ob_table_insert_op.cpp +++ b/src/sql/engine/dml/ob_table_insert_op.cpp @@ -293,7 +293,7 @@ int ObSeInsertRowIterator::setup_row_copy_mem() .set_mem_attr( ctx_.get_my_session()->get_effective_tenant_id(), ObModIds::OB_SQL_INSERT, ObCtxIds::DEFAULT_CTX_ID) .set_properties(lib::USE_TL_PAGE_OPTIONAL); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(row_copy_mem_, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(row_copy_mem_, param))) { LOG_WARN("create memory entity failed", K(ret)); } } diff --git a/src/sql/engine/dml/ob_table_insert_op.h b/src/sql/engine/dml/ob_table_insert_op.h index 0c70fa2d7..7a92f7b84 100644 --- a/src/sql/engine/dml/ob_table_insert_op.h +++ b/src/sql/engine/dml/ob_table_insert_op.h @@ -124,7 +124,7 @@ private: int64_t estimate_rows_; int64_t row_count_; int64_t index_; - lib::MemoryContext* row_copy_mem_; + lib::MemoryContext row_copy_mem_; }; } // end namespace sql diff --git a/src/sql/engine/expr/ob_expr.cpp b/src/sql/engine/expr/ob_expr.cpp index 2e419d3db..c807e2b80 100644 --- a/src/sql/engine/expr/ob_expr.cpp +++ b/src/sql/engine/expr/ob_expr.cpp @@ -100,7 +100,7 @@ OB_DEF_DESERIALIZE(ObExpr) expr_ctx_id_); if (OB_SUCC(ret)) { if (ObExprExtraInfoFactory::is_registered(type_)) { - if (OB_FAIL(ObExprExtraInfoFactory::alloc(CURRENT_CONTEXT.get_arena_allocator(), type_, extra_info_))) { + if (OB_FAIL(ObExprExtraInfoFactory::alloc(CURRENT_CONTEXT->get_arena_allocator(), type_, extra_info_))) { LOG_WARN("fail to alloc expr extra info", K(ret), K(type_)); } else if (OB_NOT_NULL(extra_info_)) { if (OB_FAIL(extra_info_->deserialize(buf, data_len, pos))) { diff --git a/src/sql/engine/expr/ob_expr.h b/src/sql/engine/expr/ob_expr.h index a04f4119b..e92ad995e 100644 --- a/src/sql/engine/expr/ob_expr.h +++ b/src/sql/engine/expr/ob_expr.h @@ -753,7 +753,7 @@ inline int decode(const char* buf, const int64_t data_len, int64_t& pos, const O array.data_ = NULL; } else { const int64_t alloc_size = sizeof(*array.data_) * array.cnt_; - array.data_ = static_cast(CURRENT_CONTEXT.get_arena_allocator().alloc(alloc_size)); + array.data_ = static_cast(CURRENT_CONTEXT->get_arena_allocator().alloc(alloc_size)); if (OB_ISNULL(array.data_)) { ret = OB_ALLOCATE_MEMORY_FAILED; SQL_LOG(WARN, "alloc memory failed", K(ret), K(alloc_size)); diff --git a/src/sql/engine/expr/ob_infix_expression.cpp b/src/sql/engine/expr/ob_infix_expression.cpp index 57c865c8b..142390b25 100644 --- a/src/sql/engine/expr/ob_infix_expression.cpp +++ b/src/sql/engine/expr/ob_infix_expression.cpp @@ -49,7 +49,7 @@ OB_DEF_SERIALIZE(ObInfixExprItem) OB_DEF_DESERIALIZE(ObInfixExprItem) { int ret = OB_SUCCESS; - if (OB_FAIL(ObPostExprItem::deserialize(CURRENT_CONTEXT.get_arena_allocator(), buf, data_len, pos))) { + if (OB_FAIL(ObPostExprItem::deserialize(CURRENT_CONTEXT->get_arena_allocator(), buf, data_len, pos))) { LOG_WARN("expr item deserialize failed", K(ret)); } else { bool param_lazy = false; diff --git a/src/sql/engine/join/ob_hash_join.h b/src/sql/engine/join/ob_hash_join.h index 294816f7d..8e068277c 100644 --- a/src/sql/engine/join/ob_hash_join.h +++ b/src/sql/engine/join/ob_hash_join.h @@ -467,7 +467,7 @@ public: PartHashJoinTable hash_table_; HashTableCell* cur_tuple_; // null or last matched tuple common::ObNewRow cur_left_row_; // like cur_row_ in operator, get row from rowstore - lib::MemoryContext* mem_context_; + lib::MemoryContext mem_context_; common::ObIAllocator* alloc_; // for buckets bool need_cache_info_; common::ObSEArray equal_cond_info_; @@ -625,7 +625,7 @@ inline int ObHashJoin::ObPartHashJoinCtx::init_mem_context(uint64_t tenant_id) lib::ContextParam param; param.set_properties(lib::USE_TL_PAGE_OPTIONAL) .set_mem_attr(tenant_id, common::ObModIds::OB_ARENA_HASH_JOIN, common::ObCtxIds::WORK_AREA); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mem_context_, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_context_, param))) { SQL_ENG_LOG(WARN, "create entity failed", K(ret)); } else if (OB_ISNULL(mem_context_)) { SQL_ENG_LOG(WARN, "mem entity is null", K(ret)); diff --git a/src/sql/engine/join/ob_hash_join_op.h b/src/sql/engine/join/ob_hash_join_op.h index 8566fbb17..b6eef411f 100644 --- a/src/sql/engine/join/ob_hash_join_op.h +++ b/src/sql/engine/join/ob_hash_join_op.h @@ -669,7 +669,7 @@ private: PartHashJoinTable hash_table_; HashTableCell* cur_tuple_; // null or last matched tuple common::ObNewRow cur_left_row_; // like cur_row_ in operator, get row from rowstore - lib::MemoryContext* mem_context_; + lib::MemoryContext mem_context_; common::ObIAllocator* alloc_; // for buckets ModulePageAllocator* bloom_filter_alloc_; ObGbyBloomFilter* bloom_filter_; @@ -726,7 +726,7 @@ inline int ObHashJoinOp::init_mem_context(uint64_t tenant_id) lib::ContextParam param; param.set_properties(lib::USE_TL_PAGE_OPTIONAL) .set_mem_attr(tenant_id, common::ObModIds::OB_ARENA_HASH_JOIN, common::ObCtxIds::WORK_AREA); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mem_context_, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_context_, param))) { SQL_ENG_LOG(WARN, "create entity failed", K(ret)); } else if (OB_ISNULL(mem_context_)) { SQL_ENG_LOG(WARN, "mem entity is null", K(ret)); diff --git a/src/sql/engine/join/ob_merge_join_op.cpp b/src/sql/engine/join/ob_merge_join_op.cpp index f9013811f..a15214a7b 100644 --- a/src/sql/engine/join/ob_merge_join_op.cpp +++ b/src/sql/engine/join/ob_merge_join_op.cpp @@ -671,7 +671,7 @@ int ObMergeJoinOp::trans_to_fill_cache() lib::ContextParam param; param.set_mem_attr(tenant_id, ObModIds::OB_SQL_MERGE_JOIN, ObCtxIds::WORK_AREA) .set_properties(lib::USE_TL_PAGE_OPTIONAL); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mem_context_, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_context_, param))) { LOG_WARN("create entity failed", K(ret)); } else if (OB_ISNULL(mem_context_)) { ret = OB_ERR_UNEXPECTED; diff --git a/src/sql/engine/join/ob_merge_join_op.h b/src/sql/engine/join/ob_merge_join_op.h index 746dea74e..de5fbe7ba 100644 --- a/src/sql/engine/join/ob_merge_join_op.h +++ b/src/sql/engine/join/ob_merge_join_op.h @@ -340,7 +340,7 @@ private: private: ObJoinState state_; - lib::MemoryContext* mem_context_; + lib::MemoryContext mem_context_; ObChunkDatumStore right_cache_; ObChunkDatumStore::Iterator right_cache_iter_; ObStoredJoinRow* stored_row_; diff --git a/src/sql/engine/join/ob_nested_loop_join_op.cpp b/src/sql/engine/join/ob_nested_loop_join_op.cpp index 1371b74b9..4a7052d4e 100644 --- a/src/sql/engine/join/ob_nested_loop_join_op.cpp +++ b/src/sql/engine/join/ob_nested_loop_join_op.cpp @@ -233,7 +233,7 @@ int ObNestedLoopJoinOp::group_read_left_operate() lib::ContextParam param; param.set_mem_attr(tenant_id, ObModIds::OB_SQL_NLJ_CACHE, ObCtxIds::WORK_AREA) .set_properties(lib::USE_TL_PAGE_OPTIONAL); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mem_context_, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_context_, param))) { LOG_WARN("create entity failed", K(ret)); } else if (OB_ISNULL(mem_context_)) { ret = OB_ERR_UNEXPECTED; @@ -326,7 +326,7 @@ int ObNestedLoopJoinOp::deep_copy_dynamic_obj() ParamStore& param_store = plan_ctx->get_param_store_for_update(); if (OB_ISNULL(mem_context_)) { ret = OB_INVALID_ARGUMENT; - LOG_WARN("mem entity not init", KP(mem_context_), K(ret)); + LOG_WARN("mem entity not init", K(ret)); } for (int64_t i = 0; OB_SUCC(ret) && i < param_cnt; ++i) { const ObDynamicParamSetter& rescan_param = get_spec().rescan_params_.at(i); diff --git a/src/sql/engine/join/ob_nested_loop_join_op.h b/src/sql/engine/join/ob_nested_loop_join_op.h index eae15a3e3..b48aaf6ac 100644 --- a/src/sql/engine/join/ob_nested_loop_join_op.h +++ b/src/sql/engine/join/ob_nested_loop_join_op.h @@ -97,7 +97,7 @@ private: public: ObJoinState state_; // for bnl join - lib::MemoryContext* mem_context_; + lib::MemoryContext mem_context_; ObChunkDatumStore left_store_; ObChunkDatumStore::Iterator left_store_iter_; bool is_left_end_; diff --git a/src/sql/engine/ob_exec_context.cpp b/src/sql/engine/ob_exec_context.cpp index f89ccb7d9..856991e85 100644 --- a/src/sql/engine/ob_exec_context.cpp +++ b/src/sql/engine/ob_exec_context.cpp @@ -441,9 +441,9 @@ int ObExecContext::init_eval_ctx() CK(NULL == eval_tmp_mem_); CK(NULL != my_session_); - lib::MemoryContext& current_context = + lib::MemoryContext current_context = (query_exec_ctx_ != nullptr ? query_exec_ctx_->get_mem_context() : CURRENT_CONTEXT); - WITH_CONTEXT(¤t_context) + WITH_CONTEXT(current_context) { lib::ContextParam param; param.set_properties(!use_remote_sql() ? lib::USE_TL_PAGE_OPTIONAL : lib::DEFAULT_PROPERTIES) @@ -456,10 +456,10 @@ int ObExecContext::init_eval_ctx() if (OB_ISNULL(mem = allocator_.alloc(sizeof(*eval_ctx_)))) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("alloc memory failed", K(ret)); - } else if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(eval_res_mem_, param))) { + } else if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(eval_res_mem_, param))) { LOG_WARN("create memory entity failed", K(ret)); eval_res_mem_ = NULL; - } else if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(eval_tmp_mem_, param))) { + } else if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(eval_tmp_mem_, param))) { LOG_WARN("create memory entity failed", K(ret)); eval_tmp_mem_ = NULL; } else { @@ -810,7 +810,7 @@ int ObExecContext::get_lob_fake_allocator(ObArenaAllocator*& allocator) .set_mem_attr(my_session_->get_effective_tenant_id(), common::ObModIds::OB_SQL_EXPR_CALC, common::ObCtxIds::DEFAULT_CTX_ID); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(lob_fake_allocator_, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(lob_fake_allocator_, param))) { SQL_ENG_LOG(WARN, "create entity failed", K(ret)); } } diff --git a/src/sql/engine/ob_exec_context.h b/src/sql/engine/ob_exec_context.h index 2059af974..a40b7350d 100644 --- a/src/sql/engine/ob_exec_context.h +++ b/src/sql/engine/ob_exec_context.h @@ -604,11 +604,11 @@ public: { return eval_ctx_; } - lib::MemoryContext* get_eval_res_mem() + lib::MemoryContext get_eval_res_mem() { return eval_res_mem_; } - lib::MemoryContext* get_eval_tmp_mem() + lib::MemoryContext get_eval_tmp_mem() { return eval_tmp_mem_; } @@ -788,8 +788,8 @@ protected: ObOpKitStore op_kit_store_; // expression evaluating memory and context. - lib::MemoryContext* eval_res_mem_; - lib::MemoryContext* eval_tmp_mem_; + lib::MemoryContext eval_res_mem_; + lib::MemoryContext eval_tmp_mem_; ObEvalCtx* eval_ctx_; ObQueryExecCtx* query_exec_ctx_; ObSEArray temp_ctx_; @@ -798,7 +798,7 @@ protected: ObGIPruningInfo gi_pruning_info_; ObSchedInfo sched_info_; - lib::MemoryContext* lob_fake_allocator_; + lib::MemoryContext lob_fake_allocator_; // serialize operator inputs of %root_op_ subplan if root_op_ is not NULL const ObPhyOperator* root_op_; diff --git a/src/sql/engine/ob_phy_operator.h b/src/sql/engine/ob_phy_operator.h index 935439328..3701d5bbe 100644 --- a/src/sql/engine/ob_phy_operator.h +++ b/src/sql/engine/ob_phy_operator.h @@ -373,7 +373,7 @@ public: protected: ObExecContext& exec_ctx_; - lib::MemoryContext* calc_mem_; + lib::MemoryContext calc_mem_; common::ObArenaAllocator* calc_buf_; common::ObNewRow cur_row_; common::ObNewRow* cur_rows_; @@ -899,7 +899,7 @@ inline int ObPhyOperator::ObPhyOperatorCtx::init_base(uint64_t tenant_id) lib::ContextParam param; param.set_properties(lib::USE_TL_PAGE_OPTIONAL) .set_mem_attr(tenant_id, common::ObModIds::OB_SQL_EXPR_CALC, common::ObCtxIds::DEFAULT_CTX_ID); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(calc_mem_, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(calc_mem_, param))) { SQL_ENG_LOG(WARN, "create entity failed", K(ret)); } else { calc_buf_ = &calc_mem_->get_arena_allocator(); diff --git a/src/sql/engine/ob_physical_plan.cpp b/src/sql/engine/ob_physical_plan.cpp index 24ad01cac..172ad6dd7 100644 --- a/src/sql/engine/ob_physical_plan.cpp +++ b/src/sql/engine/ob_physical_plan.cpp @@ -47,8 +47,8 @@ ObPhysicalPlan::ObPhysicalPlan(MemoryContext& mem_context /* = CURRENT_CONTEXT * root_op_spec_(NULL), param_count_(0), signature_(0), - field_columns_(mem_context.get_arena_allocator()), - param_columns_(mem_context.get_arena_allocator()), + field_columns_(mem_context->get_arena_allocator()), + param_columns_(mem_context->get_arena_allocator()), autoinc_params_(allocator_), stmt_need_privs_(allocator_), stmt_ora_need_privs_(allocator_), @@ -404,7 +404,7 @@ int ObPhysicalPlan::set_field_columns(const ColumnsFieldArray& fields) { int ret = OB_SUCCESS; ObField field; - WITH_CONTEXT(&mem_context_) + WITH_CONTEXT(mem_context_) { int64_t N = fields.count(); if (N > 0 && OB_FAIL(field_columns_.reserve(N))) { @@ -439,7 +439,7 @@ int ObPhysicalPlan::set_param_fields(const common::ParamsFieldArray& params) { int ret = OB_SUCCESS; int64_t N = params.count(); - WITH_CONTEXT(&mem_context_) + WITH_CONTEXT(mem_context_) { if (N > 0 && OB_FAIL(param_columns_.reserve(N))) { LOG_WARN("failed to reserved param field", K(ret)); diff --git a/src/sql/engine/px/ob_dfo.cpp b/src/sql/engine/px/ob_dfo.cpp index 83740e387..fb6ae00e9 100644 --- a/src/sql/engine/px/ob_dfo.cpp +++ b/src/sql/engine/px/ob_dfo.cpp @@ -882,16 +882,16 @@ int ObPxRpcInitTaskArgs::init_deserialize_param(lib::MemoryContext& mem_context, int ret = OB_SUCCESS; void* plan_buf = NULL; void* ctx_buf = NULL; - if (OB_ISNULL(plan_buf = mem_context.get_arena_allocator().alloc(sizeof(ObPhysicalPlan)))) { + if (OB_ISNULL(plan_buf = mem_context->get_arena_allocator().alloc(sizeof(ObPhysicalPlan)))) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("allocate memory failed", K(ret)); - } else if (OB_ISNULL(ctx_buf = mem_context.get_arena_allocator().alloc(sizeof(ObDesExecContext)))) { + } else if (OB_ISNULL(ctx_buf = mem_context->get_arena_allocator().alloc(sizeof(ObDesExecContext)))) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("allocate memory failed", K(ret)); } else { des_phy_plan_ = new (plan_buf) ObPhysicalPlan(mem_context); exec_ctx_ = new (ctx_buf) ObDesExecContext(gctx.session_mgr_); - des_allocator_ = &mem_context.get_arena_allocator(); + des_allocator_ = &mem_context->get_arena_allocator(); } return ret; } diff --git a/src/sql/engine/px/ob_px_sqc_handler.cpp b/src/sql/engine/px/ob_px_sqc_handler.cpp index 081b7a753..172f09918 100644 --- a/src/sql/engine/px/ob_px_sqc_handler.cpp +++ b/src/sql/engine/px/ob_px_sqc_handler.cpp @@ -177,7 +177,7 @@ int ObPxSqcHandler::init() .set_parallel(4) .set_properties(lib::ALLOC_THREAD_SAFE); ObIAllocator* allocator = nullptr; - if (OB_FAIL(ROOT_CONTEXT.CREATE_CONTEXT(mem_context_, param))) { + if (OB_FAIL(ROOT_CONTEXT->CREATE_CONTEXT(mem_context_, param))) { LOG_WARN("create memory entity failed", K(ret)); } else if (OB_ISNULL(mem_context_)) { ret = OB_ERR_UNEXPECTED; @@ -198,7 +198,7 @@ int ObPxSqcHandler::init() } else if (OB_ISNULL(buf = allocator->alloc(sizeof(ObPhysicalPlan)))) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("Failed to alloc physical plan", K(ret)); - } else if (FALSE_IT(des_phy_plan_ = new (buf) ObPhysicalPlan(*mem_context_))) { + } else if (FALSE_IT(des_phy_plan_ = new (buf) ObPhysicalPlan(mem_context_))) { } else if (OB_ISNULL(buf = allocator->alloc(sizeof(ObPxRpcInitSqcArgs)))) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("Failed to alloc sqc init args", K(ret)); diff --git a/src/sql/engine/px/ob_px_sqc_handler.h b/src/sql/engine/px/ob_px_sqc_handler.h index 711b632a5..9d6cd2115 100644 --- a/src/sql/engine/px/ob_px_sqc_handler.h +++ b/src/sql/engine/px/ob_px_sqc_handler.h @@ -185,7 +185,7 @@ private: }; private: - lib::MemoryContext* mem_context_; + lib::MemoryContext mem_context_; uint64_t tenant_id_; int64_t reserved_px_thread_count_; uint64_t process_flags_; diff --git a/src/sql/engine/px/ob_px_worker.cpp b/src/sql/engine/px/ob_px_worker.cpp index a47e330fe..9841c6dab 100644 --- a/src/sql/engine/px/ob_px_worker.cpp +++ b/src/sql/engine/px/ob_px_worker.cpp @@ -118,7 +118,7 @@ void PxWorkerFunctor::operator()() { int ret = OB_SUCCESS; ObPxSqcHandler* sqc_handler = task_arg_.get_sqc_handler(); - lib::MemoryContext* mem_context = nullptr; + lib::MemoryContext mem_context = nullptr; const bool enable_trace_log = lib::is_trace_log_enabled(); if (OB_NOT_NULL(sqc_handler) && OB_NOT_NULL(env_arg_.get_trace_id())) { @@ -139,7 +139,7 @@ void PxWorkerFunctor::operator()() { CREATE_WITH_TEMP_ENTITY(RESOURCE_OWNER, sqc_handler->get_tenant_id()) { - if (OB_FAIL(ROOT_CONTEXT.CREATE_CONTEXT( + if (OB_FAIL(ROOT_CONTEXT->CREATE_CONTEXT( mem_context, lib::ContextParam().set_mem_attr(lib::current_tenant_id(), ObModIds::OB_SQL_PX)))) { LOG_WARN("create memory entity failed", K(ret)); } else { @@ -147,7 +147,7 @@ void PxWorkerFunctor::operator()() { lib::ContextTLOptGuard guard(true); ObPxRpcInitTaskArgs runtime_arg; - if (OB_FAIL(runtime_arg.init_deserialize_param(*mem_context, *env_arg_.get_gctx()))) { + if (OB_FAIL(runtime_arg.init_deserialize_param(mem_context, *env_arg_.get_gctx()))) { LOG_WARN("fail to init args", K(ret)); } else if (OB_FAIL(runtime_arg.deep_copy_assign(task_arg_, mem_context->get_arena_allocator()))) { (void)ObInterruptUtil::interrupt_qc(task_arg_.task_, ret); diff --git a/src/sql/engine/sort/ob_sort_impl.cpp b/src/sql/engine/sort/ob_sort_impl.cpp index 430b6c473..9bcca1e39 100644 --- a/src/sql/engine/sort/ob_sort_impl.cpp +++ b/src/sql/engine/sort/ob_sort_impl.cpp @@ -233,7 +233,7 @@ int ObSortImpl::init(const uint64_t tenant_id, const SortColumns& sort_columns, lib::ContextParam param; param.set_mem_attr(tenant_id, ObModIds::OB_SQL_SORT_ROW, ObCtxIds::WORK_AREA) .set_properties(lib::USE_TL_PAGE_OPTIONAL); - if (NULL == mem_context_ && OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mem_context_, param))) { + if (NULL == mem_context_ && OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_context_, param))) { LOG_WARN("create entity failed", K(ret)); } else if (NULL == mem_context_) { ret = OB_ERR_UNEXPECTED; diff --git a/src/sql/engine/sort/ob_sort_impl.h b/src/sql/engine/sort/ob_sort_impl.h index 520143652..322e565f0 100644 --- a/src/sql/engine/sort/ob_sort_impl.h +++ b/src/sql/engine/sort/ob_sort_impl.h @@ -148,7 +148,7 @@ public: protected: class MemEntifyFreeGuard { public: - explicit MemEntifyFreeGuard(lib::MemoryContext*& entify) : entify_(entify) + explicit MemEntifyFreeGuard(lib::MemoryContext& entify) : entify_(entify) {} ~MemEntifyFreeGuard() { @@ -157,7 +157,7 @@ protected: entify_ = NULL; } } - lib::MemoryContext*& entify_; + lib::MemoryContext& entify_; }; class Compare { public: @@ -268,7 +268,7 @@ protected: bool need_rewind_; bool got_first_row_; bool sorted_; - lib::MemoryContext* mem_context_; + lib::MemoryContext mem_context_; MemEntifyFreeGuard mem_entify_guard_; int64_t tenant_id_; const SortColumns* sort_columns_; diff --git a/src/sql/engine/sort/ob_sort_op_impl.cpp b/src/sql/engine/sort/ob_sort_op_impl.cpp index 79566556c..1697e8873 100644 --- a/src/sql/engine/sort/ob_sort_op_impl.cpp +++ b/src/sql/engine/sort/ob_sort_op_impl.cpp @@ -197,7 +197,7 @@ int ObSortOpImpl::init(const uint64_t tenant_id, const ObIArrayCREATE_CONTEXT(mem_context_, param))) { LOG_WARN("create entity failed", K(ret)); } else if (NULL == mem_context_) { ret = OB_ERR_UNEXPECTED; diff --git a/src/sql/engine/sort/ob_sort_op_impl.h b/src/sql/engine/sort/ob_sort_op_impl.h index 762780c24..9733111f5 100644 --- a/src/sql/engine/sort/ob_sort_op_impl.h +++ b/src/sql/engine/sort/ob_sort_op_impl.h @@ -212,7 +212,7 @@ public: protected: class MemEntifyFreeGuard { public: - explicit MemEntifyFreeGuard(lib::MemoryContext*& entify) : entify_(entify) + explicit MemEntifyFreeGuard(lib::MemoryContext& entify) : entify_(entify) {} ~MemEntifyFreeGuard() { @@ -221,7 +221,7 @@ protected: entify_ = NULL; } } - lib::MemoryContext*& entify_; + lib::MemoryContext& entify_; }; int get_next_row(const common::ObIArray& exprs, const ObChunkDatumStore::StoredRow*& sr) @@ -282,7 +282,7 @@ protected: bool need_rewind_; bool got_first_row_; bool sorted_; - lib::MemoryContext* mem_context_; + lib::MemoryContext mem_context_; MemEntifyFreeGuard mem_entify_guard_; int64_t tenant_id_; const ObIArray* sort_collations_; diff --git a/src/sql/engine/subquery/ob_subplan_filter_op.cpp b/src/sql/engine/subquery/ob_subplan_filter_op.cpp index baa92a0b5..98845854d 100644 --- a/src/sql/engine/subquery/ob_subplan_filter_op.cpp +++ b/src/sql/engine/subquery/ob_subplan_filter_op.cpp @@ -451,7 +451,7 @@ int ObSubPlanFilterOp::handle_update_set() lib::ContextParam param; param.set_mem_attr(ctx_.get_my_session()->get_effective_tenant_id(), ObModIds::OB_SQL_EXECUTOR, ObCtxIds::WORK_AREA) .set_properties(lib::USE_TL_PAGE_OPTIONAL); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(update_set_mem_, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(update_set_mem_, param))) { LOG_WARN("create memory entity failed", K(ret)); } } else { diff --git a/src/sql/engine/subquery/ob_subplan_filter_op.h b/src/sql/engine/subquery/ob_subplan_filter_op.h index c1d894ffb..585f86393 100644 --- a/src/sql/engine/subquery/ob_subplan_filter_op.h +++ b/src/sql/engine/subquery/ob_subplan_filter_op.h @@ -126,7 +126,7 @@ private: private: common::ObSEArray subplan_iters_; - lib::MemoryContext* update_set_mem_; + lib::MemoryContext update_set_mem_; }; } // end namespace sql diff --git a/src/sql/engine/table/ob_table_scan.cpp b/src/sql/engine/table/ob_table_scan.cpp index 5b7abe97a..9c8475aed 100644 --- a/src/sql/engine/table/ob_table_scan.cpp +++ b/src/sql/engine/table/ob_table_scan.cpp @@ -265,8 +265,8 @@ int ObTableScan::ObTableScanCtx::init_table_allocator(ObExecContext& ctx) lib::ContextParam param; param.set_mem_attr(my_session->get_effective_tenant_id(), ObModIds::OB_SQL_EXECUTOR, ObCtxIds::DEFAULT_CTX_ID) .set_properties(lib::USE_TL_PAGE_OPTIONAL); - MemoryContext* mem_context = nullptr; - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mem_context, param))) { + lib::MemoryContext mem_context = nullptr; + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_context, param))) { LOG_WARN("fail to create entity", K(ret)); } else if (OB_ISNULL(mem_context)) { ret = OB_ERR_UNEXPECTED; @@ -276,12 +276,12 @@ int ObTableScan::ObTableScanCtx::init_table_allocator(ObExecContext& ctx) } } if (OB_SUCC(ret)) { - MemoryContext* mem_context = nullptr; + lib::MemoryContext mem_context = nullptr; lib::ContextParam param; param.set_mem_attr(my_session->get_effective_tenant_id(), ObModIds::OB_TABLE_SCAN_ITER, ObCtxIds::DEFAULT_CTX_ID) .set_properties(lib::USE_TL_PAGE_OPTIONAL) .set_ablock_size(lib::INTACT_MIDDLE_AOBJECT_SIZE); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mem_context, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_context, param))) { LOG_WARN("fail to create entity", K(ret)); } else if (OB_ISNULL(mem_context)) { ret = OB_ERR_UNEXPECTED; diff --git a/src/sql/engine/table/ob_table_scan.h b/src/sql/engine/table/ob_table_scan.h index ff5c42cf9..978a98ee2 100644 --- a/src/sql/engine/table/ob_table_scan.h +++ b/src/sql/engine/table/ob_table_scan.h @@ -151,7 +151,7 @@ public: { table_allocator_ = alloc; } - inline void set_scan_iterator_mementity(lib::MemoryContext* mem) + inline void set_scan_iterator_mementity(lib::MemoryContext mem) { scan_param_.iterator_mementity_ = mem; scan_param_.allocator_ = &mem->get_arena_allocator(); diff --git a/src/sql/engine/table/ob_table_scan_op.cpp b/src/sql/engine/table/ob_table_scan_op.cpp index 94790420a..34083c1bf 100644 --- a/src/sql/engine/table/ob_table_scan_op.cpp +++ b/src/sql/engine/table/ob_table_scan_op.cpp @@ -136,8 +136,8 @@ int ObTableScanOp::init_table_allocator() param.set_mem_attr(my_session->get_effective_tenant_id(), ObModIds::OB_SQL_EXECUTOR, ObCtxIds::DEFAULT_CTX_ID) .set_properties(lib::USE_TL_PAGE_OPTIONAL) .set_ablock_size(lib::INTACT_MIDDLE_AOBJECT_SIZE); - MemoryContext* mem_context = nullptr; - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mem_context, param))) { + lib::MemoryContext mem_context = nullptr; + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_context, param))) { LOG_WARN("fail to create entity", K(ret)); } else if (OB_ISNULL(mem_context)) { ret = OB_ERR_UNEXPECTED; @@ -146,12 +146,12 @@ int ObTableScanOp::init_table_allocator() table_allocator_ = &mem_context->get_arena_allocator(); } if (OB_SUCC(ret)) { - MemoryContext* mem_context = nullptr; + lib::MemoryContext mem_context = nullptr; lib::ContextParam param; param.set_mem_attr(my_session->get_effective_tenant_id(), ObModIds::OB_TABLE_SCAN_ITER, ObCtxIds::DEFAULT_CTX_ID) .set_properties(lib::USE_TL_PAGE_OPTIONAL) .set_ablock_size(lib::INTACT_MIDDLE_AOBJECT_SIZE); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mem_context, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_context, param))) { LOG_WARN("fail to create entity", K(ret)); } else if (OB_ISNULL(mem_context)) { ret = OB_ERR_UNEXPECTED; diff --git a/src/sql/executor/ob_remote_executor_processor.h b/src/sql/executor/ob_remote_executor_processor.h index 41c94d67d..6c150afb9 100644 --- a/src/sql/executor/ob_remote_executor_processor.h +++ b/src/sql/executor/ob_remote_executor_processor.h @@ -24,7 +24,7 @@ public: ObRemoteBaseExecuteP(const observer::ObGlobalContext& gctx, bool is_execute_remote_plan = false) : obrpc::ObRpcProcessor(), gctx_(gctx), - exec_ctx_(CURRENT_CONTEXT.get_arena_allocator(), gctx.session_mgr_), + exec_ctx_(CURRENT_CONTEXT->get_arena_allocator(), gctx.session_mgr_), vt_iter_factory_(*gctx_.vt_iter_creator_), sql_ctx_(), trans_state_(), diff --git a/src/sql/ob_query_exec_ctx_mgr.cpp b/src/sql/ob_query_exec_ctx_mgr.cpp index bac3dc404..53f38ed6c 100644 --- a/src/sql/ob_query_exec_ctx_mgr.cpp +++ b/src/sql/ob_query_exec_ctx_mgr.cpp @@ -23,7 +23,7 @@ ObQueryExecCtx* ObQueryExecCtx::alloc(ObSQLSessionInfo& session) { int ret = OB_SUCCESS; ObQueryExecCtx* query_ctx = nullptr; - MemoryContext* entity = nullptr; + MemoryContext entity = nullptr; if (OB_ISNULL(entity = session.get_ctx_mem_context())) { ObMemAttr mem_attr; mem_attr.tenant_id_ = session.get_effective_tenant_id(); @@ -36,7 +36,7 @@ ObQueryExecCtx* ObQueryExecCtx::alloc(ObSQLSessionInfo& session) .set_ablock_size(lib::INTACT_MIDDLE_AOBJECT_SIZE); // Memory entity used by result set may be accessed across threads during // asynchronous execution, so we must use ROOT_CONTEXT - if (OB_FAIL(ROOT_CONTEXT.CREATE_CONTEXT(entity, param))) { + if (OB_FAIL(ROOT_CONTEXT->CREATE_CONTEXT(entity, param))) { LOG_WARN("create entity failed", K(ret), K(mem_attr)); } else if (NULL == entity) { ret = OB_ERR_UNEXPECTED; @@ -47,7 +47,7 @@ ObQueryExecCtx* ObQueryExecCtx::alloc(ObSQLSessionInfo& session) session.set_ctx_mem_context(nullptr); } if (OB_SUCC(ret)) { - if (OB_ISNULL(query_ctx = op_reclaim_alloc_args(ObQueryExecCtx, session, *entity))) { + if (OB_ISNULL(query_ctx = op_reclaim_alloc_args(ObQueryExecCtx, session, entity))) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("allocate memory failed", K(ret), K(sizeof(ObQueryExecCtx))); } else { @@ -69,7 +69,7 @@ void ObQueryExecCtx::free(ObQueryExecCtx* query_ctx) int64_t ref_cnt = query_ctx->dec_ref_count(); if (0 == ref_cnt) { ObSQLSessionInfo& session = query_ctx->get_result_set().get_session(); - MemoryContext& mem_context = query_ctx->mem_context_; + MemoryContext mem_context = query_ctx->mem_context_; query_ctx->cache_schema_info_->try_revert_schema_guard(); query_ctx->cache_schema_info_ = NULL; op_reclaim_free(query_ctx); @@ -79,10 +79,10 @@ void ObQueryExecCtx::free(ObQueryExecCtx* query_ctx) // save memory entity to session if none memory entity in session, otherwise // destroy it. if (nullptr == session.get_ctx_mem_context()) { - mem_context.reset_remain_one_page(); - session.set_ctx_mem_context(&mem_context); + mem_context->reset_remain_one_page(); + session.set_ctx_mem_context(mem_context); } else { - DESTROY_CONTEXT(&mem_context); + DESTROY_CONTEXT(mem_context); } } } else if (ref_cnt < 0) { diff --git a/src/sql/ob_query_exec_ctx_mgr.h b/src/sql/ob_query_exec_ctx_mgr.h index fa7000777..951b44611 100644 --- a/src/sql/ob_query_exec_ctx_mgr.h +++ b/src/sql/ob_query_exec_ctx_mgr.h @@ -74,7 +74,7 @@ public: private: ObQueryExecCtx(ObSQLSessionInfo& session, lib::MemoryContext& mem_context) : mem_context_(mem_context), - result_set_(session, mem_context.get_arena_allocator()), + result_set_(session, mem_context->get_arena_allocator()), ref_count_(0), cur_task_ctx_(nullptr), cache_schema_info_(NULL) @@ -83,7 +83,7 @@ private: {} private: - lib::MemoryContext& mem_context_; + lib::MemoryContext mem_context_; observer::ObMySQLResultSet result_set_; volatile int64_t ref_count_; ObITaskExecCtx* cur_task_ctx_; diff --git a/src/sql/ob_sql.cpp b/src/sql/ob_sql.cpp index 91dffcb5f..b39c62550 100644 --- a/src/sql/ob_sql.cpp +++ b/src/sql/ob_sql.cpp @@ -2389,7 +2389,7 @@ int ObSql::transform_stmt_with_outline( // So we use a memory context to do that CREATE_WITH_TEMP_CONTEXT(param) { - ObIAllocator& tmp_allocator = CURRENT_CONTEXT.get_arena_allocator(); + ObIAllocator& tmp_allocator = CURRENT_CONTEXT->get_arena_allocator(); ObMaxConcurrentParam::FixParamStore fix_param_store( OB_MALLOC_NORMAL_BLOCK_SIZE, ObWrapperAllocator(&tmp_allocator)); if (OB_FAIL(ObSQLUtils::get_outline_key( @@ -2462,7 +2462,7 @@ int ObSql::get_outline_info( int64_t sql_buf_size = pc_ctx.raw_sql_.get_serialize_size(); int64_t sql_pos = 0; char* sql_buf = NULL; - ObIAllocator& allocator = CURRENT_CONTEXT.get_arena_allocator(); + ObIAllocator& allocator = CURRENT_CONTEXT->get_arena_allocator(); if (OB_ISNULL(sql_buf = (char*)allocator.alloc(sql_buf_size))) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("failed to allocate memory", K(ret)); diff --git a/src/sql/ob_sql_utils.cpp b/src/sql/ob_sql_utils.cpp index db68723b1..dc98f06f3 100644 --- a/src/sql/ob_sql_utils.cpp +++ b/src/sql/ob_sql_utils.cpp @@ -630,7 +630,7 @@ int ObSQLUtils::calc_const_expr(ObSQLSessionInfo* session, const ObRawExpr* expr .set_page_size(OB_MALLOC_BIG_BLOCK_SIZE); CREATE_WITH_TEMP_CONTEXT(param) { - ObIAllocator& tmp_allocator = CURRENT_CONTEXT.get_arena_allocator(); + ObIAllocator& tmp_allocator = CURRENT_CONTEXT->get_arena_allocator(); ObPhysicalPlanCtx phy_plan_ctx(tmp_allocator); for (int i = 0; OB_SUCC(ret) && i < params.count(); i++) { if (OB_FAIL(phy_plan_ctx.get_param_store_for_update().push_back(params.at(i)))) { diff --git a/src/sql/optimizer/ob_log_plan.cpp b/src/sql/optimizer/ob_log_plan.cpp index 598cbcaae..2f9ad4147 100644 --- a/src/sql/optimizer/ob_log_plan.cpp +++ b/src/sql/optimizer/ob_log_plan.cpp @@ -5364,7 +5364,7 @@ int ObLogPlan::plan_tree_traverse(const TraverseOp& operation, void* ctx) } else { NumberingCtx numbering_ctx; // operator numbering context NumberingExchangeCtx numbering_exchange_ctx; // operator numbering context - ObArenaAllocator allocator(CURRENT_CONTEXT.get_malloc_allocator()); + ObArenaAllocator allocator(CURRENT_CONTEXT->get_malloc_allocator()); allocator.set_label("PlanTreeTraver"); ObAllocExprContext alloc_expr_ctx(allocator); // expr allocation context AllocExchContext alloc_exch_ctx(parallel); // exchange allocation context diff --git a/src/sql/optimizer/ob_px_resource_analyzer.cpp b/src/sql/optimizer/ob_px_resource_analyzer.cpp index ddc82f561..9c7e426d6 100644 --- a/src/sql/optimizer/ob_px_resource_analyzer.cpp +++ b/src/sql/optimizer/ob_px_resource_analyzer.cpp @@ -162,7 +162,7 @@ int DfoInfo::get_child(int64_t idx, DfoInfo*& child) // =================================================================================== // =================================================================================== -ObPxResourceAnalyzer::ObPxResourceAnalyzer() : dfo_allocator_(CURRENT_CONTEXT.get_malloc_allocator()) +ObPxResourceAnalyzer::ObPxResourceAnalyzer() : dfo_allocator_(CURRENT_CONTEXT->get_malloc_allocator()) { dfo_allocator_.set_label("PxResourceAnaly"); } diff --git a/src/sql/optimizer/ob_table_location.cpp b/src/sql/optimizer/ob_table_location.cpp index ece5407cb..235a3992c 100644 --- a/src/sql/optimizer/ob_table_location.cpp +++ b/src/sql/optimizer/ob_table_location.cpp @@ -1693,7 +1693,7 @@ int ObTableLocation::calculate_partition_ids_fast_for_non_insert( K(query_range.get_table_grapth().key_part_head_->pos_.column_type_.get_collation_type())); } else { if (type1 != type2 && ob_is_string_tc(type1) == ob_is_string_tc(type2)) { - ObArenaAllocator allocator(CURRENT_CONTEXT.get_malloc_allocator()); + ObArenaAllocator allocator(CURRENT_CONTEXT->get_malloc_allocator()); allocator.set_label("CalcNoInsert"); ObExprCtx expr_ctx; const ObObj* cast_result = NULL; @@ -1785,7 +1785,7 @@ int ObTableLocation::calculate_partition_ids_fast_for_insert( K(key_cvt_item.get_expr_operator()->get_result_type().get_collation_type())); } else { if (type1 != type2 && ob_is_string_tc(type1) == ob_is_string_tc(type2)) { - ObArenaAllocator allocator(CURRENT_CONTEXT.get_malloc_allocator()); + ObArenaAllocator allocator(CURRENT_CONTEXT->get_malloc_allocator()); allocator.set_label("CalcInsert"); ObExprCtx expr_ctx; const ObObj* cast_result = NULL; @@ -2178,7 +2178,7 @@ int ObTableLocation::calc_partition_ids_by_in_expr(ObExecContext& exec_ctx, comm LOG_WARN("Failed to push back partition id", K(ret)); } } else { - ObArenaAllocator allocator(CURRENT_CONTEXT.get_malloc_allocator()); + ObArenaAllocator allocator(CURRENT_CONTEXT->get_malloc_allocator()); allocator.set_label("CalcByInExpr"); ObExprCtx expr_ctx; ObNewRow part_row; @@ -3561,7 +3561,7 @@ int ObTableLocation::calc_query_range_partition_ids(ObExecContext& exec_ctx, com } else { all_part = false; ObQueryRangeArray query_ranges; - ObArenaAllocator allocator(CURRENT_CONTEXT.get_malloc_allocator()); + ObArenaAllocator allocator(CURRENT_CONTEXT->get_malloc_allocator()); allocator.set_label("CalcQRPartIds"); bool is_all_single_value_ranges = true; if (OB_FAIL(calc_node->pre_query_range_.get_tablet_ranges( @@ -3635,7 +3635,7 @@ int ObTableLocation::calc_func_value_partition_ids(ObExecContext& exec_ctx, comm } if (OB_SUCC(ret)) { ObObj tmp; - ObArenaAllocator allocator(CURRENT_CONTEXT.get_malloc_allocator()); + ObArenaAllocator allocator(CURRENT_CONTEXT->get_malloc_allocator()); allocator.set_label("CalcFVPartIds"); ObCastCtx cast_ctx(&allocator, &dtc_params, CM_NONE, calc_node->res_type_.get_collation_type()); ObExprCtx expr_ctx; @@ -3692,7 +3692,7 @@ int ObTableLocation::calc_column_value_partition_ids(ObExecContext& exec_ctx, co if (OB_SUCC(ret)) { ObObj tmp; ObExprCtx expr_ctx; - ObArenaAllocator allocator(CURRENT_CONTEXT.get_malloc_allocator()); + ObArenaAllocator allocator(CURRENT_CONTEXT->get_malloc_allocator()); allocator.set_label("CalcCVPartIds"); ObCastCtx cast_ctx(&allocator, &dtc_params, CM_NONE, calc_node->res_type_.get_collation_type()); bool is_strict = false; @@ -3746,7 +3746,7 @@ int ObTableLocation::calc_partition_ids_by_stored_expr(ObExecContext& exec_ctx, K_(part_level), K(subkey_conv_exprs_.count())); } else { - ObArenaAllocator allocator(CURRENT_CONTEXT.get_malloc_allocator()); + ObArenaAllocator allocator(CURRENT_CONTEXT->get_malloc_allocator()); allocator.set_label("CalcStoredExpr"); ObExprCtx expr_ctx; ObNewRow part_row; @@ -3919,7 +3919,7 @@ int ObTableLocation::calc_partition_ids_by_ranges(ObExecContext& exec_ctx, commo LOG_WARN("Failed to get part ids by ranges", K(ret)); } } else { - ObArenaAllocator allocator(CURRENT_CONTEXT.get_malloc_allocator()); + ObArenaAllocator allocator(CURRENT_CONTEXT->get_malloc_allocator()); allocator.set_label("CalcByRanges"); ObExprCtx expr_ctx; if (OB_FAIL(ObSQLUtils::wrap_expr_ctx(stmt_type_, exec_ctx, allocator, expr_ctx))) { @@ -4284,7 +4284,7 @@ int ObTableLocation::calc_partition_id_by_row(ObExecContext& exec_ctx, common::O int ret = OB_SUCCESS; ObObj func_result; ObTaskExecutorCtx* tctx = NULL; - ObArenaAllocator allocator(CURRENT_CONTEXT.get_malloc_allocator()); + ObArenaAllocator allocator(CURRENT_CONTEXT->get_malloc_allocator()); allocator.set_label("CalcByRow"); ObExprCtx expr_ctx; if (OB_FAIL(ObSQLUtils::wrap_expr_ctx(stmt_type_, exec_ctx, allocator, expr_ctx))) { @@ -4911,7 +4911,7 @@ int ObTableLocation::calc_up_key_exprs_partition_id(ObExecContext& exec_ctx, ObP int ret = OB_SUCCESS; const int64_t key_count = key_exprs.count(); cross_part = false; - ObArenaAllocator allocator(CURRENT_CONTEXT.get_malloc_allocator()); + ObArenaAllocator allocator(CURRENT_CONTEXT->get_malloc_allocator()); allocator.set_label("CalcUpKey"); ObNewRow part_row; ObExprCtx expr_ctx; diff --git a/src/sql/parser/ob_parser.cpp b/src/sql/parser/ob_parser.cpp index 0ead19b78..54065002b 100644 --- a/src/sql/parser/ob_parser.cpp +++ b/src/sql/parser/ob_parser.cpp @@ -94,7 +94,7 @@ int ObParser::split_multiple_stmt( int tmp_ret = OB_SUCCESS; bool need_continue = true; while (remain > 0 && OB_SUCC(ret) && !parse_stat.parse_fail_ && need_continue) { - ObArenaAllocator allocator(CURRENT_CONTEXT.get_malloc_allocator()); + ObArenaAllocator allocator(CURRENT_CONTEXT->get_malloc_allocator()); allocator.set_label("SplitMultiStmt"); ObIAllocator* bak_allocator = allocator_; allocator_ = &allocator; diff --git a/src/sql/plan_cache/ob_cache_object.cpp b/src/sql/plan_cache/ob_cache_object.cpp index 5768a7416..8c71926b0 100644 --- a/src/sql/plan_cache/ob_cache_object.cpp +++ b/src/sql/plan_cache/ob_cache_object.cpp @@ -28,7 +28,7 @@ using namespace share::schema; namespace sql { ObCacheObject::ObCacheObject(ObCacheObjType co_type, lib::MemoryContext& mem_context /* = CURRENT_CONTEXT */) : mem_context_(mem_context), - allocator_(mem_context.get_safe_arena_allocator()), + allocator_(mem_context->get_safe_arena_allocator()), type_(co_type), ref_count_(0), tenant_schema_version_(OB_INVALID_VERSION), diff --git a/src/sql/plan_cache/ob_cache_object.h b/src/sql/plan_cache/ob_cache_object.h index 724e951a3..819d53654 100644 --- a/src/sql/plan_cache/ob_cache_object.h +++ b/src/sql/plan_cache/ob_cache_object.h @@ -351,7 +351,7 @@ private: int64_t dec_ref_count(const CacheRefHandleID ref_handle); protected: - lib::MemoryContext& mem_context_; + lib::MemoryContext mem_context_; common::ObIAllocator& allocator_; ObCacheObjType type_; volatile int64_t ref_count_; diff --git a/src/sql/plan_cache/ob_cache_object_factory.cpp b/src/sql/plan_cache/ob_cache_object_factory.cpp index c0b24e187..828cb62b8 100644 --- a/src/sql/plan_cache/ob_cache_object_factory.cpp +++ b/src/sql/plan_cache/ob_cache_object_factory.cpp @@ -61,12 +61,12 @@ int ObCacheObjectFactory::alloc( mem_attr.label_ = ObNewModIds::OB_SQL_PHY_PLAN; } mem_attr.ctx_id_ = ObCtxIds::PLAN_CACHE_CTX_ID; - MemoryContext* entity = NULL; + MemoryContext entity = NULL; if (OB_UNLIKELY(co_type < T_CO_SQL_CRSR) || OB_UNLIKELY(co_type >= T_CO_MAX) || OB_ISNULL(plan_cache)) { ret = OB_INVALID_ARGUMENT; LOG_WARN("co_type is invalid", K(co_type), K(plan_cache), K(tenant_id)); - } else if (OB_FAIL(ROOT_CONTEXT.CREATE_CONTEXT(entity, lib::ContextParam().set_mem_attr(mem_attr)))) { + } else if (OB_FAIL(ROOT_CONTEXT->CREATE_CONTEXT(entity, lib::ContextParam().set_mem_attr(mem_attr)))) { LOG_WARN("create entity failed", K(ret), K(mem_attr)); } else if (NULL == entity) { ret = OB_ERR_UNEXPECTED; @@ -79,7 +79,7 @@ int ObCacheObjectFactory::alloc( switch (co_type) { case T_CO_SQL_CRSR: if (NULL != (buf = entity->get_arena_allocator().alloc(sizeof(ObPhysicalPlan)))) { - cache_obj = new (buf) ObPhysicalPlan(*entity); + cache_obj = new (buf) ObPhysicalPlan(entity); } break; case T_CO_ANON: @@ -180,13 +180,13 @@ void ObCacheObjectFactory::inner_free(ObCacheObject* cache_obj) { int ret = OB_SUCCESS; - MemoryContext& entity = cache_obj->get_mem_context(); - WITH_CONTEXT(&entity) + MemoryContext entity = cache_obj->get_mem_context(); + WITH_CONTEXT(entity) { cache_obj->~ObCacheObject(); } cache_obj = NULL; - DESTROY_CONTEXT(&entity); + DESTROY_CONTEXT(entity); } ObPlanCache* ObCacheObjectFactory::get_plan_cache(const uint64_t tenant_id) diff --git a/src/sql/plan_cache/ob_ps_cache.cpp b/src/sql/plan_cache/ob_ps_cache.cpp index fa8df35bb..26f447689 100644 --- a/src/sql/plan_cache/ob_ps_cache.cpp +++ b/src/sql/plan_cache/ob_ps_cache.cpp @@ -87,7 +87,7 @@ int ObPsCache::init(const int64_t hash_bucket, const common::ObAddr addr, ObModIds::OB_HASH_NODE_PS_INFO, tenant_id))) { LOG_WARN("FAILED TO INIT sql_plan_map", K(ret)); - } else if (OB_FAIL(ROOT_CONTEXT.CREATE_CONTEXT(mem_context_, param))) { + } else if (OB_FAIL(ROOT_CONTEXT->CREATE_CONTEXT(mem_context_, param))) { LOG_WARN("create memory entity failed", K(ret)); } else if (OB_ISNULL(mem_context_)) { ret = OB_ERR_UNEXPECTED; diff --git a/src/sql/plan_cache/ob_ps_cache.h b/src/sql/plan_cache/ob_ps_cache.h index 5da8ee209..d9e4f04dd 100644 --- a/src/sql/plan_cache/ob_ps_cache.h +++ b/src/sql/plan_cache/ob_ps_cache.h @@ -187,7 +187,7 @@ private: uint64_t hit_count_; uint64_t access_count_; - lib::MemoryContext* mem_context_; + lib::MemoryContext mem_context_; common::ObIAllocator* inner_allocator_; }; diff --git a/src/sql/resolver/expr/ob_raw_expr.h b/src/sql/resolver/expr/ob_raw_expr.h index 5791150d3..7f0495e7e 100644 --- a/src/sql/resolver/expr/ob_raw_expr.h +++ b/src/sql/resolver/expr/ob_raw_expr.h @@ -707,7 +707,7 @@ private: ret = OB_INIT_TWICE; SQL_RESV_LOG(WARN, "init twice", K(ret)); } else if (auto_free) { - block_allocator_ = &CURRENT_CONTEXT.get_arena_allocator(); + block_allocator_ = &CURRENT_CONTEXT->get_arena_allocator(); } else { void* alloc_buf = NULL; if (OB_ISNULL(alloc_buf = ob_malloc(sizeof(ObArenaAllocator), ObModIds::OB_BIT_SET))) { diff --git a/src/sql/rewrite/ob_transform_rule.cpp b/src/sql/rewrite/ob_transform_rule.cpp index 4a5f895f1..e68254ba0 100644 --- a/src/sql/rewrite/ob_transform_rule.cpp +++ b/src/sql/rewrite/ob_transform_rule.cpp @@ -204,7 +204,7 @@ int ObTransformRule::evaluate_cost(common::ObIArray& parent_stm ObOptimizerPartitionLocationCache optimizer_location_cache(*ctx_->allocator_, ctx_->partition_location_cache_); ObDMLStmt* optimizer_stmt = NULL; ObDMLStmt* temp_stmt = NULL; - lib::MemoryContext* mem_context = nullptr; + lib::MemoryContext mem_context = nullptr; lib::ContextParam param; param.set_mem_attr(session_info->get_effective_tenant_id(), "CostBasedRewrit", ObCtxIds::DEFAULT_CTX_ID) .set_properties(lib::USE_TL_PAGE_OPTIONAL) @@ -219,7 +219,7 @@ int ObTransformRule::evaluate_cost(common::ObIArray& parent_stm LOG_WARN("failed to transform heuristic rule", K(ret)); } else if (OB_FAIL(temp_stmt->check_and_convert_hint(*session_info))) { LOG_WARN("failed to check and convert hint", K(ret)); - } else if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mem_context, param))) { + } else if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_context, param))) { LOG_WARN("failed to create memory entity", K(ret)); } else if (OB_ISNULL(mem_context)) { ret = OB_ERR_UNEXPECTED; diff --git a/src/sql/rewrite/ob_transform_utils.cpp b/src/sql/rewrite/ob_transform_utils.cpp index 9ccc1945e..08227785f 100644 --- a/src/sql/rewrite/ob_transform_utils.cpp +++ b/src/sql/rewrite/ob_transform_utils.cpp @@ -2846,12 +2846,12 @@ int ObTransformUtils::check_exprs_unique_on_table_items(ObDMLStmt* stmt, ObSQLSe ret = OB_ERR_UNEXPECTED; LOG_WARN("unexpected null", K(ret)); } else { - MemoryContext* mem_entity = NULL; + lib::MemoryContext mem_entity = NULL; lib::ContextParam param; param.set_mem_attr(ObMemAttr(session_info->get_effective_tenant_id(), "CheckUnique")); param.set_properties(lib::USE_TL_PAGE_OPTIONAL); param.set_page_size(OB_MALLOC_NORMAL_BLOCK_SIZE); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mem_entity, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_entity, param))) { LOG_WARN("failed to create memory entity", K(ret)); } else if (OB_ISNULL(mem_entity)) { ret = OB_ERR_UNEXPECTED; @@ -2953,12 +2953,12 @@ int ObTransformUtils::check_stmt_unique(ObSelectStmt* stmt, ObSQLSessionInfo* se if (OB_FAIL(ret) || is_unique || !need_check) { /*do nothing*/ } else { - MemoryContext* mem_entity = NULL; + lib::MemoryContext mem_entity = NULL; lib::ContextParam param; param.set_mem_attr(ObMemAttr(session_info->get_effective_tenant_id(), "CheckUnique")); param.set_properties(lib::USE_TL_PAGE_OPTIONAL); param.set_page_size(OB_MALLOC_NORMAL_BLOCK_SIZE); - if (OB_FAIL(CURRENT_CONTEXT.CREATE_CONTEXT(mem_entity, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_entity, param))) { LOG_WARN("failed to create memory entity", K(ret)); } else if (OB_ISNULL(mem_entity)) { ret = OB_ERR_UNEXPECTED; diff --git a/src/sql/session/ob_sql_session_info.h b/src/sql/session/ob_sql_session_info.h index 73e52707f..0e81addcc 100644 --- a/src/sql/session/ob_sql_session_info.h +++ b/src/sql/session/ob_sql_session_info.h @@ -531,11 +531,11 @@ public: use_static_typing_engine_ = use; } - void set_ctx_mem_context(lib::MemoryContext* ctx_mem_context) + void set_ctx_mem_context(lib::MemoryContext ctx_mem_context) { ctx_mem_context_ = ctx_mem_context; } - lib::MemoryContext* get_ctx_mem_context() + lib::MemoryContext get_ctx_mem_context() { return ctx_mem_context_; } @@ -700,7 +700,7 @@ private: ObSessionStat session_stat_; - lib::MemoryContext* ctx_mem_context_; + lib::MemoryContext ctx_mem_context_; common::ObSEArray enable_role_array_; ObTenantCachedSchemaGuardInfo cached_schema_guard_info_; bool in_definer_named_proc_; diff --git a/src/storage/ob_dml_param.h b/src/storage/ob_dml_param.h index 7fa7a547d..5020bd849 100644 --- a/src/storage/ob_dml_param.h +++ b/src/storage/ob_dml_param.h @@ -128,7 +128,7 @@ public: : common::ObVTableScanParam(), trans_desc_(NULL), table_param_(NULL), - allocator_(&CURRENT_CONTEXT.get_arena_allocator()), + allocator_(&CURRENT_CONTEXT->get_arena_allocator()), part_filter_(NULL), part_mgr_(NULL), column_orders_(nullptr), @@ -143,7 +143,7 @@ public: : common::ObVTableScanParam(), trans_desc_(&trans_desc), table_param_(NULL), - allocator_(&CURRENT_CONTEXT.get_arena_allocator()), + allocator_(&CURRENT_CONTEXT->get_arena_allocator()), part_filter_(NULL), part_mgr_(NULL), column_orders_(nullptr), @@ -170,7 +170,7 @@ public: int16_t block_cache_hit_rate_; uint64_t ref_table_id_; // main table id ObIPartitionGroupGuard* partition_guard_; - lib::MemoryContext* iterator_mementity_; + lib::MemoryContext iterator_mementity_; OB_INLINE virtual bool is_valid() const { return (NULL != trans_desc_ && trans_desc_->is_valid_or_standalone_stmt() && ObVTableScanParam::is_valid()); diff --git a/src/storage/ob_i_store.cpp b/src/storage/ob_i_store.cpp index 501b45467..651920f2f 100644 --- a/src/storage/ob_i_store.cpp +++ b/src/storage/ob_i_store.cpp @@ -963,8 +963,8 @@ int ObTableAccessContext::init(ObTableScanParam& scan_param, const ObStoreCtx& c { int ret = OB_SUCCESS; - lib::MemoryContext& current_mem = - (NULL == scan_param.iterator_mementity_) ? CURRENT_CONTEXT : *scan_param.iterator_mementity_; + lib::MemoryContext current_mem = + (NULL == scan_param.iterator_mementity_) ? CURRENT_CONTEXT : scan_param.iterator_mementity_; lib::ContextParam param; param .set_mem_attr( @@ -979,11 +979,11 @@ int ObTableAccessContext::init(ObTableScanParam& scan_param, const ObStoreCtx& c LOG_WARN("invalid argument", K(ret), "pkey", scan_param.pkey_); } else if (NULL != scan_mem_) { // reused, do nothing. - } else if (OB_FAIL(current_mem.CREATE_CONTEXT(scan_mem_, param))) { + } else if (OB_FAIL(current_mem->CREATE_CONTEXT(scan_mem_, param))) { LOG_WARN("fail to create entity", K(ret)); } if (OB_SUCC(ret)) { - stmt_mem_ = ¤t_mem; + stmt_mem_ = current_mem; stmt_allocator_ = &stmt_mem_->get_arena_allocator(); allocator_ = &scan_mem_->get_arena_allocator(); pkey_ = scan_param.pkey_; @@ -1489,7 +1489,7 @@ int ObRowsInfo::init( const ObRelativeTable& table, const ObStoreCtx& store_ctx, const ObIArray& col_descs) { int ret = OB_SUCCESS; - lib::MemoryContext& current_mem = CURRENT_CONTEXT; + lib::MemoryContext current_mem = CURRENT_CONTEXT; lib::ContextParam param; param @@ -1499,7 +1499,7 @@ int ObRowsInfo::init( if (OB_UNLIKELY(is_inited_)) { ret = OB_INIT_TWICE; STORAGE_LOG(WARN, "ObRowsinfo init twice", K(ret)); - } else if (OB_FAIL(current_mem.CREATE_CONTEXT(scan_mem_, param))) { + } else if (OB_FAIL(current_mem->CREATE_CONTEXT(scan_mem_, param))) { LOG_WARN("fail to create entity", K(ret)); } else if (OB_ISNULL(scan_mem_)) { ret = OB_ERR_UNEXPECTED; diff --git a/src/storage/ob_i_store.h b/src/storage/ob_i_store.h index 7cb763fda..68db02820 100644 --- a/src/storage/ob_i_store.h +++ b/src/storage/ob_i_store.h @@ -1363,7 +1363,7 @@ struct ObTableAccessContext { int init(const common::ObQueryFlag& query_flag, const ObStoreCtx& ctx, common::ObArenaAllocator& allocator, const common::ObVersionRange& trans_version_range); TO_STRING_KV(K_(is_inited), K_(timeout), K_(pkey), K_(query_flag), K_(sql_mode), KP_(store_ctx), KP_(expr_ctx), - KP_(limit_param), KP_(stmt_allocator), KP_(allocator), KP_(stmt_mem), KP_(scan_mem), KP_(table_scan_stat), + KP_(limit_param), KP_(stmt_allocator), KP_(allocator), KP_(table_scan_stat), KP_(block_cache_ws), K_(out_cnt), K_(is_end), K_(trans_version_range), KP_(row_filter), K_(merge_log_ts), K_(read_out_type), K_(lob_locator_helper)); @@ -1383,8 +1383,8 @@ public: common::ObArenaAllocator* stmt_allocator_; // storage scan/rescan interface level allocator, will be reclaimed in every scan/rescan call common::ObArenaAllocator* allocator_; - lib::MemoryContext* stmt_mem_; // sql statement level memory entity, only for query - lib::MemoryContext* scan_mem_; // scan/rescan level memory entity, only for query + lib::MemoryContext stmt_mem_; // sql statement level memory entity, only for query + lib::MemoryContext scan_mem_; // scan/rescan level memory entity, only for query common::ObTableScanStatistic* table_scan_stat_; blocksstable::ObBlockCacheWorkingSet* block_cache_ws_; ObTableAccessStat access_stat_; @@ -1512,7 +1512,7 @@ public: private: common::ObStoreRowkey min_key_; - lib::MemoryContext* scan_mem_; // scan/rescan level memory entity, only for query + lib::MemoryContext scan_mem_; // scan/rescan level memory entity, only for query int64_t delete_count_; bool collation_free_transformed_; int16_t rowkey_column_num_; diff --git a/unittest/sql/optimizer/test_optimizer_utils.cpp b/unittest/sql/optimizer/test_optimizer_utils.cpp index 5e7ae3ed7..6dab012fa 100644 --- a/unittest/sql/optimizer/test_optimizer_utils.cpp +++ b/unittest/sql/optimizer/test_optimizer_utils.cpp @@ -538,12 +538,12 @@ int MockCacheObjectFactory::alloc(ObCacheObject*& cache_obj, ObCacheObjType co_t mem_attr.label_ = ObNewModIds::OB_SQL_PHY_PLAN; } mem_attr.ctx_id_ = ObCtxIds::PLAN_CACHE_CTX_ID; - MemoryContext* entity = NULL; + lib::MemoryContext entity = NULL; if (OB_UNLIKELY(co_type < T_CO_SQL_CRSR) || OB_UNLIKELY(co_type >= T_CO_MAX)) { ret = OB_INVALID_ARGUMENT; LOG_WARN("co_type is invalid", K(co_type)); - } else if (OB_FAIL(ROOT_CONTEXT.CREATE_CONTEXT(entity, lib::ContextParam().set_mem_attr(mem_attr)))) { + } else if (OB_FAIL(ROOT_CONTEXT->CREATE_CONTEXT(entity, lib::ContextParam().set_mem_attr(mem_attr)))) { LOG_WARN("create entity failed", K(ret), K(mem_attr)); } else if (NULL == entity) { ret = OB_ERR_UNEXPECTED; @@ -556,7 +556,7 @@ int MockCacheObjectFactory::alloc(ObCacheObject*& cache_obj, ObCacheObjType co_t switch (co_type) { case T_CO_SQL_CRSR: if (NULL != (buf = entity->get_arena_allocator().alloc(sizeof(ObPhysicalPlan)))) { - cache_obj = new (buf) ObPhysicalPlan(*entity); + cache_obj = new (buf) ObPhysicalPlan(entity); } break; case T_CO_ANON: @@ -593,7 +593,7 @@ void MockCacheObjectFactory::free(ObCacheObject* cache_obj) if (OB_ISNULL(cache_obj)) { // nothing to do } else { - MemoryContext& entity = cache_obj->get_mem_context(); + lib::MemoryContext entity = cache_obj->get_mem_context(); int64_t ref_count = cache_obj->dec_ref_count(PLAN_GEN_HANDLE); if (ref_count > 0) { // nothing todo @@ -610,13 +610,13 @@ void MockCacheObjectFactory::inner_free(ObCacheObject* cache_obj) { int ret = OB_SUCCESS; - MemoryContext& entity = cache_obj->get_mem_context(); - WITH_CONTEXT(&entity) + lib::MemoryContext entity = cache_obj->get_mem_context(); + WITH_CONTEXT(entity) { cache_obj->~ObCacheObject(); } cache_obj = NULL; - DESTROY_CONTEXT(&entity); + DESTROY_CONTEXT(entity); } } // end of namespace test diff --git a/unittest/sql/resolver/expr/test_raw_expr_resolver.cpp b/unittest/sql/resolver/expr/test_raw_expr_resolver.cpp index 3799998c1..925702e42 100644 --- a/unittest/sql/resolver/expr/test_raw_expr_resolver.cpp +++ b/unittest/sql/resolver/expr/test_raw_expr_resolver.cpp @@ -63,7 +63,7 @@ void TestRawExprResolver::resolve(const char* expr, const char*& json_expr) ObArray aggr_exprs; ObArray win_exprs; const char* expr_str = expr; - ObIAllocator& allocator = CURRENT_CONTEXT.get_arena_allocator(); + ObIAllocator& allocator = CURRENT_CONTEXT->get_arena_allocator(); ObRawExprFactory expr_factory(allocator); ObTimeZoneInfo tz_info; ObNameCaseMode case_mode = OB_NAME_CASE_INVALID; diff --git a/unittest/sql/rewrite/test_query_range.cpp b/unittest/sql/rewrite/test_query_range.cpp index c6f38c1c7..1dce985bf 100644 --- a/unittest/sql/rewrite/test_query_range.cpp +++ b/unittest/sql/rewrite/test_query_range.cpp @@ -288,7 +288,7 @@ ObQueryRangeTest::ObQueryRangeTest() column_id3_(18), allocator_(ObModIds::TEST), expr_factory_(allocator_), - params_((ObWrapperAllocator(CURRENT_CONTEXT.get_arena_allocator()))), + params_((ObWrapperAllocator(CURRENT_CONTEXT->get_arena_allocator()))), ref_col_(table_id_, column_id1_, T_REF_COLUMN) {} @@ -501,7 +501,7 @@ void ObQueryRangeTest::get_query_range(const char* sql_expr, const char*& json_e ObGetMethodArray get_methods; ObRawExpr* expr = NULL; ObArray range_columns; - ParamStore params((ObWrapperAllocator(CURRENT_CONTEXT.get_arena_allocator()))); + ParamStore params((ObWrapperAllocator(CURRENT_CONTEXT->get_arena_allocator()))); ObArenaAllocator allocator(ObModIds::TEST); const ObDataTypeCastParams dtc_params; ObQueryRange pre_query_range; @@ -570,7 +570,7 @@ void ObQueryRangeTest::get_query_range_filter( ObGetMethodArray get_methods; ObRawExpr* expr = NULL; ObArray range_columns; - ParamStore params((ObWrapperAllocator(CURRENT_CONTEXT.get_arena_allocator()))); + ParamStore params((ObWrapperAllocator(CURRENT_CONTEXT->get_arena_allocator()))); ObArenaAllocator allocator(ObModIds::TEST); const ObDataTypeCastParams dtc_params; ObQueryRange pre_query_range; @@ -623,7 +623,7 @@ void ObQueryRangeTest::get_query_range_collation(const char* sql_expr, const cha char var[100][100]; ObQueryRangeArray ranges; ObGetMethodArray get_methods; - ParamStore params((ObWrapperAllocator(CURRENT_CONTEXT.get_arena_allocator()))); + ParamStore params((ObWrapperAllocator(CURRENT_CONTEXT->get_arena_allocator()))); const ObDataTypeCastParams dtc_params; char final_sql[100]; get_final_sql(sql_expr, final_sql, params, var);