add double-destroy check for MemoryContext

This commit is contained in:
jg0 2021-07-27 19:54:14 +08:00 committed by wangzelin.wzl
parent 91852f9b58
commit 0b7773c43f
86 changed files with 416 additions and 329 deletions

View File

@ -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<MemoryContext*>(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));

View File

@ -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_;

View File

@ -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),

View File

@ -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_;

View File

@ -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),

View File

@ -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 <typename T, int64_t LOCAL_ARRAY_SIZE, typename BlockAllocatorT, bool auto_free>

View File

@ -55,11 +55,11 @@ public:
template <typename BlockAllocatorT>
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 <typename T, int64_t LOCAL_ARRAY_SIZE, typename BlockAllocatorT, bool auto_free>

View File

@ -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)

View File

@ -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 {

View File

@ -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

View File

@ -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 &param, 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<MemoryContext*>((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 <typename... Args>
int create_context(MemoryContext*& context, const DynamicInfo& di, Args&&... args)
template<typename ... Args>
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 <typename... Args>
int create_context(MemoryContext& context, const DynamicInfo& di, Args&&... args)
template<typename ... Args>
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<char[sizeof(Flow)]> buf;
Flow* flow = new (&buf[0]) Flow(MemoryContext::root());
static CoVar<char [sizeof(Flow)]> 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<ContextSource::WITH> : 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<ContextSource::CREATE> : public _SBase {
public:
template <typename... Args>
_S(const bool condition, Args&&... args) : _SBase(), context_(nullptr), flow_(nullptr)
template<typename ... Args>
_S(const bool condition, Args && ... args)
: _SBase(), flow_(nullptr)
{
int ret = common::OB_SUCCESS;
if (OB_LIKELY(condition)) {
MemoryContext* tmp_context = reinterpret_cast<MemoryContext*>(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

View File

@ -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()

View File

@ -11,12 +11,12 @@
*/
#define USING_LOG_PREFIX SHARE
#include <gtest/gtest.h>
#define private public
#define protected public
#include "lib/rc/context.h"
#undef private
#undef protected
#include <gtest/gtest.h>
#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));

View File

@ -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));

View File

@ -276,7 +276,7 @@ int ObMPStmtExecute::save_exception_for_arraybinding(
exception.pos_ = pos;
exception.error_code_ = static_cast<uint16_t>(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<ParamStore*>(alloc.alloc(sizeof(ParamStore))))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("failed to allocate memory", K(ret));

View File

@ -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());

View File

@ -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<common::ObString, int64_t, common::hash::NoPthreadDefendMode> 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_;

View File

@ -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()
{

View File

@ -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);
}
}
}

View File

@ -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;

View File

@ -91,7 +91,7 @@ private:
NoSwapCache;
typedef common::ObKVCache<ObSchemaCacheKey, ObSchemaCacheValue> KVCache;
lib::MemoryContext* mem_context_;
lib::MemoryContext mem_context_;
NoSwapCache sys_cache_;
KVCache cache_;
bool is_inited_;

View File

@ -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;

View File

@ -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<HashRow*, OB_MALLOC_BIG_BLOCK_SIZE, common::ModulePageAllocator>;
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_;

View File

@ -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<ObGbyPartition> 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;

View File

@ -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;

View File

@ -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<DatumStoreLinkPartition> dumped_group_parts_;
ObChunkDatumStore group_store_;

View File

@ -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<HashCol> hash_table_;
@ -544,7 +544,7 @@ inline int ObBasicHashPartInfrastructure<HashCol, HashRowStore>::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));

View File

@ -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<HashCol> hash_table_;
@ -552,7 +552,7 @@ inline int ObHashPartInfrastructure<HashCol, HashRowStore>::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));

View File

@ -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;

View File

@ -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_;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -161,7 +161,7 @@ public:
private:
ObConnectByPump connect_by_pump_;
lib::MemoryContext* mem_context_;
lib::MemoryContext mem_context_;
ObSqlWorkAreaProfile profile_;
ObSqlMemMgrProcessor sql_mem_processor_;
};

View File

@ -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));
}
}

View File

@ -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

View File

@ -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))) {

View File

@ -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<T*>(CURRENT_CONTEXT.get_arena_allocator().alloc(alloc_size));
array.data_ = static_cast<T*>(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));

View File

@ -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;

View File

@ -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<EqualConditionInfo*, 16> 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));

View File

@ -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));

View File

@ -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;

View File

@ -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_;

View File

@ -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);

View File

@ -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_;

View File

@ -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(&current_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));
}
}

View File

@ -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<ObSqlTempTableCtx, 1> 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_;

View File

@ -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();

View File

@ -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));

View File

@ -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;
}

View File

@ -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));

View File

@ -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_;

View File

@ -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);

View File

@ -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;

View File

@ -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_;

View File

@ -197,7 +197,7 @@ int ObSortOpImpl::init(const uint64_t tenant_id, const ObIArray<ObSortFieldColla
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;

View File

@ -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<ObExpr*>& 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<ObSortFieldCollation>* sort_collations_;

View File

@ -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 {

View File

@ -126,7 +126,7 @@ private:
private:
common::ObSEArray<Iterator*, 16> subplan_iters_;
lib::MemoryContext* update_set_mem_;
lib::MemoryContext update_set_mem_;
};
} // end namespace sql

View File

@ -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;

View File

@ -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();

View File

@ -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;

View File

@ -24,7 +24,7 @@ public:
ObRemoteBaseExecuteP(const observer::ObGlobalContext& gctx, bool is_execute_remote_plan = false)
: obrpc::ObRpcProcessor<T>(),
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_(),

View File

@ -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) {

View File

@ -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_;

View File

@ -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));

View File

@ -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)))) {

View File

@ -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

View File

@ -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");
}

View File

@ -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;

View File

@ -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;

View File

@ -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),

View File

@ -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_;

View File

@ -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)

View File

@ -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;

View File

@ -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_;
};

View File

@ -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))) {

View File

@ -204,7 +204,7 @@ int ObTransformRule::evaluate_cost(common::ObIArray<ObParentDMLStmt>& 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<ObParentDMLStmt>& 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;

View File

@ -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;

View File

@ -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<uint64_t, 8> enable_role_array_;
ObTenantCachedSchemaGuardInfo cached_schema_guard_info_;
bool in_definer_named_proc_;

View File

@ -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());

View File

@ -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_ = &current_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<share::schema::ObColDesc>& 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;

View File

@ -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_;

View File

@ -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

View File

@ -63,7 +63,7 @@ void TestRawExprResolver::resolve(const char* expr, const char*& json_expr)
ObArray<ObAggFunRawExpr*> aggr_exprs;
ObArray<ObWinFunRawExpr*> 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;

View File

@ -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<ColumnItem> 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<ColumnItem> 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);