diff --git a/src/gausskernel/storage/mot/core/storage/index/masstree/mot_masstree_kvthread.cpp b/src/gausskernel/storage/mot/core/storage/index/masstree/mot_masstree_kvthread.cpp index 91c6f0bba..5874893e8 100644 --- a/src/gausskernel/storage/mot/core/storage/index/masstree/mot_masstree_kvthread.cpp +++ b/src/gausskernel/storage/mot/core/storage/index/masstree/mot_masstree_kvthread.cpp @@ -54,13 +54,27 @@ inline threadinfo::threadinfo(int purpose, int index, int rcu_max_free_count) ts_ = 2; } +// if rcu_max_free_count == -1, destroy threadinfo structure threadinfo* threadinfo::make(void* obj_mem, int purpose, int index, int rcu_max_free_count) { - threadinfo* ti = new (obj_mem) threadinfo(purpose, index, rcu_max_free_count); + if (rcu_max_free_count == -1) { + // act as destructor + MOT_ASSERT(obj_mem); + threadinfo* ti = (threadinfo*)obj_mem; + masstree_invariant(ti->dealloc_rcu.size() == 0); + delete ti; + return nullptr; + } + + threadinfo* ti = new (std::nothrow) threadinfo(purpose, index, rcu_max_free_count); + if (ti == nullptr) { + return nullptr; + } if (use_pool()) { void* limbo_space = ti->allocate(MAX_MEMTAG_MASSTREE_LIMBO_GROUP_ALLOCATION_SIZE, memtag_limbo); if (!limbo_space) { + delete ti; return nullptr; } diff --git a/src/gausskernel/storage/mot/core/system/common/session_context.cpp b/src/gausskernel/storage/mot/core/system/common/session_context.cpp index 7b5e7eb97..17dd6f341 100644 --- a/src/gausskernel/storage/mot/core/system/common/session_context.cpp +++ b/src/gausskernel/storage/mot/core/system/common/session_context.cpp @@ -95,13 +95,14 @@ extern void ClearCurrentNumaNodeId() extern bool InitMasstreeThreadinfo() { if (mtSessionThreadInfo == nullptr) { - mtSessionThreadInfo = (threadinfo*)malloc(sizeof(threadinfo)); - + MOT_LOG_TRACE("InitMasstreeThreadinfo(): Create mtSessionThreadInfo %p. MOTCurrThreadId: %u\n", + mtSessionThreadInfo, + MOTCurrThreadId); + mtSessionThreadInfo = + threadinfo::make(mtSessionThreadInfo, threadinfo::TI_PROCESS, MOTCurrThreadId, 0 /* Create object */); if (mtSessionThreadInfo == nullptr) { return false; } - - mtSessionThreadInfo = threadinfo::make(mtSessionThreadInfo, threadinfo::TI_PROCESS, MOTCurrThreadId, 0); } return true; } @@ -109,7 +110,11 @@ extern bool InitMasstreeThreadinfo() extern void DestroyMasstreeThreadinfo() { if (mtSessionThreadInfo != nullptr) { - free(mtSessionThreadInfo); + MOT_LOG_TRACE("DestroyMasstreeThreadinfo(): Destroy mtSessionThreadInfo %p. MOTCurrThreadId: %u\n", + mtSessionThreadInfo, + MOTCurrThreadId); + + threadinfo::make(mtSessionThreadInfo, threadinfo::TI_PROCESS, MOTCurrThreadId, -1 /* Destroy object */); mtSessionThreadInfo = nullptr; } }