Fix direct load thread local variables destruct

This commit is contained in:
obdev 2023-01-29 16:17:28 +08:00 committed by ob-robot
parent b87473dac2
commit d7d52691d0
3 changed files with 61 additions and 62 deletions

View File

@ -7,11 +7,12 @@
#include "observer/table_load/ob_table_load_task_scheduler.h" #include "observer/table_load/ob_table_load_task_scheduler.h"
#include "common/ob_timeout_ctx.h" #include "common/ob_timeout_ctx.h"
#include "lib/stat/ob_session_stat.h" #include "lib/stat/ob_session_stat.h"
#include "observer/omt/ob_tenant.h"
#include "observer/table_load/ob_table_load_stat.h" #include "observer/table_load/ob_table_load_stat.h"
#include "observer/table_load/ob_table_load_task.h" #include "observer/table_load/ob_table_load_task.h"
#include "share/ob_share_util.h" #include "share/ob_share_util.h"
#include "share/rc/ob_tenant_base.h" #include "share/rc/ob_tenant_base.h"
#include "observer/omt/ob_tenant.h" #include "storage/direct_load/ob_direct_load_table_builder_allocator.h"
namespace oceanbase namespace oceanbase
{ {
@ -19,6 +20,7 @@ namespace observer
{ {
using namespace common; using namespace common;
using namespace share; using namespace share;
using namespace storage;
void ObTableLoadTaskThreadPoolScheduler::MyThreadPool::run1() void ObTableLoadTaskThreadPoolScheduler::MyThreadPool::run1()
{ {
@ -237,6 +239,9 @@ void ObTableLoadTaskThreadPoolScheduler::run(uint64_t thread_idx)
state_ = STATE_STOPPING; state_ = STATE_STOPPING;
} }
// clear thread local variables
get_table_builder_allocator()->reset();
LOG_INFO("table load task thread stopped", KP(this), "pid", get_tid_cache(), K(thread_idx)); LOG_INFO("table load task thread stopped", KP(this), "pid", get_tid_cache(), K(thread_idx));
} }

View File

@ -445,6 +445,7 @@ void ObDDLKV::reset()
{ {
FLOG_INFO("ddl kv reset", KP(this), K(*this)); FLOG_INFO("ddl kv reset", KP(this), K(*this));
is_inited_ = false; is_inited_ = false;
ObSSTable::reset();
ls_id_.reset(); ls_id_.reset();
tablet_id_.reset(); tablet_id_.reset();
ddl_start_scn_ = SCN::min_scn(); ddl_start_scn_ = SCN::min_scn();
@ -469,7 +470,6 @@ void ObDDLKV::reset()
sstable_index_builder_ = nullptr; sstable_index_builder_ = nullptr;
} }
block_meta_tree_.destroy(); block_meta_tree_.destroy();
ObSSTable::reset();
arena_allocator_.reset(); arena_allocator_.reset();
} }

View File

@ -13,34 +13,20 @@ namespace oceanbase
namespace storage namespace storage
{ {
class ObDirectLoadTableBuilderAllocator class ObDirectLoadTableBuilderAllocator final
{ {
public: public:
ObDirectLoadTableBuilderAllocator(); ObDirectLoadTableBuilderAllocator()
~ObDirectLoadTableBuilderAllocator();
template <typename T, typename... Args>
T *alloc(Args &&... args);
void free(ObIDirectLoadPartitionTableBuilder *table_builder);
void assert_in_own_thread();
private:
struct Item : public common::ObDLinkBase<Item>
{ {
char buf_[];
};
private:
int64_t tid_;
ObDList<Item> using_list_;
};
ObDirectLoadTableBuilderAllocator::ObDirectLoadTableBuilderAllocator()
{
tid_ = get_tid_cache(); tid_ = get_tid_cache();
} }
~ObDirectLoadTableBuilderAllocator()
ObDirectLoadTableBuilderAllocator::~ObDirectLoadTableBuilderAllocator() {
{ assert_in_own_thread();
OB_ASSERT(using_list_.is_empty());
}
void reset()
{
assert_in_own_thread(); assert_in_own_thread();
Item *item = nullptr; Item *item = nullptr;
DLIST_REMOVE_ALL_NORET(item, using_list_) DLIST_REMOVE_ALL_NORET(item, using_list_)
@ -51,11 +37,10 @@ ObDirectLoadTableBuilderAllocator::~ObDirectLoadTableBuilderAllocator()
ob_free(item); ob_free(item);
} }
OB_ASSERT(using_list_.is_empty()); OB_ASSERT(using_list_.is_empty());
} }
template <typename T, typename... Args>
template <typename T, typename... Args> T *alloc(Args &&... args)
T *ObDirectLoadTableBuilderAllocator::alloc(Args &&... args) {
{
assert_in_own_thread(); assert_in_own_thread();
T *t = nullptr; T *t = nullptr;
void *buf = nullptr; void *buf = nullptr;
@ -68,10 +53,9 @@ T *ObDirectLoadTableBuilderAllocator::alloc(Args &&... args)
using_list_.add_last(item); using_list_.add_last(item);
} }
return t; return t;
} }
void free(ObIDirectLoadPartitionTableBuilder *table_builder)
void ObDirectLoadTableBuilderAllocator::free(ObIDirectLoadPartitionTableBuilder *table_builder) {
{
assert_in_own_thread(); assert_in_own_thread();
if (OB_NOT_NULL(table_builder)) { if (OB_NOT_NULL(table_builder)) {
table_builder->~ObIDirectLoadPartitionTableBuilder(); table_builder->~ObIDirectLoadPartitionTableBuilder();
@ -80,13 +64,23 @@ void ObDirectLoadTableBuilderAllocator::free(ObIDirectLoadPartitionTableBuilder
item->~Item(); item->~Item();
ob_free(item); ob_free(item);
} }
} }
OB_INLINE void assert_in_own_thread()
void ObDirectLoadTableBuilderAllocator::assert_in_own_thread() {
{
const int64_t tid = get_tid_cache(); const int64_t tid = get_tid_cache();
OB_ASSERT(tid == tid_); OB_ASSERT(tid == tid_);
} }
private:
struct Item : public common::ObDLinkBase<Item>
{
char buf_[];
};
private:
int64_t tid_;
ObDList<Item> using_list_;
};
OB_INLINE ObDirectLoadTableBuilderAllocator *get_table_builder_allocator() OB_INLINE ObDirectLoadTableBuilderAllocator *get_table_builder_allocator()
{ {