Fix table store cache problem when query splitting tablet

This commit is contained in:
Hongqin-Li
2025-03-21 08:46:18 +00:00
committed by ob-robot
parent 221cc6295c
commit aedbcbf4a7
3 changed files with 72 additions and 6 deletions

View File

@ -4233,6 +4233,7 @@ int ObTablet::get_split_src_read_table_if_need(
ObLSHandle ls_handle;
ObTabletHandle src_tablet_handle;
ObTablet *src_tablet = nullptr;
ObStorageMetaHandle *meta_handle = nullptr;
if (OB_ISNULL(ls_service = MTL(ObLSService*))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("failed to get ObLSService from MTL", K(ret), KP(ls_service));
@ -4245,10 +4246,15 @@ int ObTablet::get_split_src_read_table_if_need(
LOG_WARN("tablet handle obj is nullptr", K(ret));
} else if (OB_FAIL(iter.add_split_extra_tablet_handle(src_tablet_handle))) {
LOG_WARN("fail to set split src tabelt handle", K(ret));
} else if (OB_FAIL(iter.table_store_iter_.alloc_split_extra_table_store_handle(meta_handle))) {
LOG_WARN("failed to alloc split extra table store handle", K(ret));
} else if (OB_ISNULL(meta_handle)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("invalid meta handle", K(ret));
} else if (OB_FAIL(src_tablet->get_read_tables_(
snapshot_version,
iter.table_store_iter_,
iter.table_store_iter_.table_store_handle_,
*meta_handle,
ObGetReadTablesMode::NORMAL))) {
LOG_WARN("failed to get read tables from table store", K(ret), KPC(src_tablet));
} else {
@ -4298,11 +4304,17 @@ int ObTablet::get_split_dst_read_table(
for (int64_t i = 0; OB_SUCC(ret) && i < dst_tablet_ids.count(); ++i) {
const ObTabletID &dst_tablet_id = dst_tablet_ids.at(i);
ObTablet *dst_tablet = nullptr;
ObStorageMetaHandle *meta_handle = nullptr;
if (OB_FAIL(ls_handle.get_ls()->get_tablet(dst_tablet_ids.at(i), dst_tablet_handle, timeout,
ObMDSGetTabletMode::READ_READABLE_COMMITED))) {
LOG_WARN("failed to get tablet", K(ret), K(dst_tablet_ids.at(i)), K(tablet_meta_.ls_id_));
} else if (OB_FAIL(iter.add_split_extra_tablet_handle(dst_tablet_handle))) {
LOG_WARN("fail to set split src tablet handle", K(ret));
} else if (OB_FAIL(iter.table_store_iter_.alloc_split_extra_table_store_handle(meta_handle))) {
LOG_WARN("failed to alloc split extra table store handle", K(ret));
} else if (OB_ISNULL(meta_handle)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("invalid meta handle", K(ret));
} else if (OB_FALSE_IT(dst_tablet = dst_tablet_handle.get_obj())) {
} else if (dst_tablet->get_tablet_meta().table_store_flag_.with_major_sstable()) {
ObTabletCreateDeleteMdsUserData user_data;
@ -4317,7 +4329,7 @@ int ObTablet::get_split_dst_read_table(
} else if (OB_FAIL(dst_tablet_handle.get_obj()->get_read_tables_(
snapshot_version,
iter.table_store_iter_,
iter.table_store_iter_.table_store_handle_,
*meta_handle,
ObGetReadTablesMode::SKIP_MAJOR))) {
LOG_WARN("failed to get read tables from table store", K(ret), K(dst_tablet_ids.at(i)));
} else {

View File

@ -29,7 +29,8 @@ ObTableStoreIterator::ObTableStoreIterator(const bool reverse, const bool need_l
table_ptr_array_(),
pos_(INT64_MAX),
memstore_retired_(nullptr),
transfer_src_table_store_handle_(nullptr)
transfer_src_table_store_handle_(nullptr),
split_extra_table_store_handles_(nullptr)
{
step_ = reverse ? -1 : 1;
sstable_handle_array_.set_attr(ObMemAttr(MTL_ID(), "TblHdlArray"));
@ -79,6 +80,30 @@ int ObTableStoreIterator::assign(const ObTableStoreIterator& other)
*transfer_src_table_store_handle_ = *(other.transfer_src_table_store_handle_);
}
}
if (OB_FAIL(ret)) {
} else if (OB_UNLIKELY(nullptr != other.split_extra_table_store_handles_)) {
if (nullptr == split_extra_table_store_handles_) {
void *meta_hdl_buf = ob_malloc(sizeof(ObArray<ObStorageMetaHandle>), ObMemAttr(MTL_ID(), "SplitTblMetaH"));
if (OB_ISNULL(meta_hdl_buf)) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("fail to allocator memory for handle", K(ret));
} else {
split_extra_table_store_handles_ = new (meta_hdl_buf) ObArray<ObStorageMetaHandle>();
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(split_extra_table_store_handles_->assign(*other.split_extra_table_store_handles_))) {
LOG_WARN("failed to assign split extra table store handles", K(ret));
}
}
} else {
if (OB_UNLIKELY(nullptr != split_extra_table_store_handles_)) {
split_extra_table_store_handles_->~ObIArray<ObStorageMetaHandle>();
ob_free(split_extra_table_store_handles_);
split_extra_table_store_handles_ = nullptr;
}
}
}
return ret;
}
@ -99,6 +124,11 @@ void ObTableStoreIterator::reset()
ob_free(transfer_src_table_store_handle_);
transfer_src_table_store_handle_ = nullptr;
}
if (nullptr != split_extra_table_store_handles_) {
split_extra_table_store_handles_->~ObIArray<ObStorageMetaHandle>();
ob_free(split_extra_table_store_handles_);
split_extra_table_store_handles_ = nullptr;
}
pos_ = INT64_MAX;
memstore_retired_ = nullptr;
}
@ -126,9 +156,9 @@ int ObTableStoreIterator::get_next(ObTableHandleV2 &table_handle)
int ret = OB_SUCCESS;
table_handle.reset();
ObITable *table = nullptr;
if (OB_UNLIKELY(nullptr != transfer_src_table_store_handle_)) {
if (OB_UNLIKELY(nullptr != transfer_src_table_store_handle_ || nullptr != split_extra_table_store_handles_)) {
ret = OB_NOT_SUPPORTED;
LOG_ERROR("doesn't support cross tablet get table handl", K(ret), KP(transfer_src_table_store_handle_));
LOG_ERROR("doesn't support cross tablet get table handl", K(ret), KP(transfer_src_table_store_handle_), KP(split_extra_table_store_handles_));
} else if (OB_FAIL(inner_move_idx_to_next())) {
} else {
if (OB_FAIL(get_ith_table(pos_, table))) {
@ -207,6 +237,28 @@ int ObTableStoreIterator::set_handle(const ObStorageMetaHandle &table_store_hand
return ret;
}
int ObTableStoreIterator::alloc_split_extra_table_store_handle(ObStorageMetaHandle *&meta_handle)
{
int ret = OB_SUCCESS;
meta_handle = nullptr;
if (nullptr == split_extra_table_store_handles_) {
void *meta_hdl_buf = ob_malloc(sizeof(ObArray<ObStorageMetaHandle>), ObMemAttr(MTL_ID(), "SplitTblMetaH"));
if (OB_ISNULL(meta_hdl_buf)) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("fail to allocator memory for handle", K(ret));
} else {
split_extra_table_store_handles_ = new (meta_hdl_buf) ObArray<ObStorageMetaHandle>();
}
}
if (OB_FAIL(ret)) {
} else if (OB_ISNULL(meta_handle = split_extra_table_store_handles_->alloc_place_holder())) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("fail to allocator memory for handle", K(ret));
}
return ret;
}
int ObTableStoreIterator::add_table(ObITable *table)
{
int ret = OB_SUCCESS;

View File

@ -67,6 +67,7 @@ public:
void resume();
int set_handle(const ObStorageMetaHandle &table_store_handle);
int alloc_split_extra_table_store_handle(ObStorageMetaHandle *&meta_handle);
ObITable *get_last_memtable();
int get_next(ObITable *&table);
@ -85,7 +86,7 @@ public:
return (NULL == memstore_retired_) ? false : ATOMIC_LOAD(memstore_retired_);
}
TO_STRING_KV(K_(table_ptr_array), K_(sstable_handle_array), K_(pos), K_(step), K_(memstore_retired),
K_(need_load_sstable), K_(table_store_handle), KPC_(transfer_src_table_store_handle));
K_(need_load_sstable), K_(table_store_handle), KPC_(transfer_src_table_store_handle), KPC_(split_extra_table_store_handles));
private:
int inner_move_idx_to_next();
int get_table_ptr_with_meta_handle(
@ -108,6 +109,7 @@ private:
int64_t step_;
bool * memstore_retired_;
ObStorageMetaHandle *transfer_src_table_store_handle_;
ObIArray<ObStorageMetaHandle> *split_extra_table_store_handles_;
DISALLOW_COPY_AND_ASSIGN(ObTableStoreIterator);
};