From e6433a4d06dfa09c65da22b1345f220cf543e0eb Mon Sep 17 00:00:00 2001 From: obdev Date: Wed, 7 Feb 2024 11:19:15 +0000 Subject: [PATCH] replace ObProtectedMemtableMgrHandle::has_memtable to ObTablet::has_memtable --- .../compaction/ob_basic_tablet_merge_ctx.cpp | 9 ++++-- .../compaction/ob_basic_tablet_merge_ctx.h | 2 +- .../compaction/ob_tenant_tablet_scheduler.cpp | 9 ++++-- src/storage/ls/ob_freezer.cpp | 5 +++- .../meta_mem/ob_tablet_pointer_map.cpp | 8 +++--- src/storage/tablet/ob_tablet.cpp | 28 ++++++++----------- src/storage/tablet/ob_tablet.h | 1 - 7 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/storage/compaction/ob_basic_tablet_merge_ctx.cpp b/src/storage/compaction/ob_basic_tablet_merge_ctx.cpp index 1d08137bc..0feffb9aa 100644 --- a/src/storage/compaction/ob_basic_tablet_merge_ctx.cpp +++ b/src/storage/compaction/ob_basic_tablet_merge_ctx.cpp @@ -526,11 +526,11 @@ int ObBasicTabletMergeCtx::swap_tablet() return ret; } -bool ObBasicTabletMergeCtx::need_swap_tablet(const ObTablet &tablet, +bool ObBasicTabletMergeCtx::need_swap_tablet(ObProtectedMemtableMgrHandle &memtable_mgr_handle, const int64_t row_count, const int64_t macro_count) { - bool bret = tablet.has_memtable() + bool bret = memtable_mgr_handle.has_memtable() && (row_count >= LARGE_VOLUME_DATA_ROW_COUNT_THREASHOLD || macro_count >= LARGE_VOLUME_DATA_MACRO_COUNT_THREASHOLD); #ifdef ERRSIM @@ -1031,6 +1031,7 @@ int ObBasicTabletMergeCtx::swap_tablet(ObGetMergeTablesResult &get_merge_table_r LOG_WARN("ha status is not allowed major", KR(ret), KPC(this)); } else { ObTablesHandleArray &tables_handle = get_merge_table_result.handle_; + ObProtectedMemtableMgrHandle *protected_handle = NULL; int64_t row_count = 0; int64_t macro_count = 0; const ObSSTable *sstable = nullptr; @@ -1039,7 +1040,9 @@ int ObBasicTabletMergeCtx::swap_tablet(ObGetMergeTablesResult &get_merge_table_r row_count += sstable->get_row_count(); macro_count += sstable->get_data_macro_block_count(); } // end of for - if (need_swap_tablet(*get_tablet(), row_count, macro_count)) { + if (OB_FAIL(get_tablet()->get_protected_memtable_mgr_handle(protected_handle))) { + LOG_WARN("failed to get_protected_memtable_mgr_handle", K(ret), KPC(get_tablet())); + } else if (need_swap_tablet(*protected_handle, row_count, macro_count)) { tables_handle.reset(); // clear tables array if (OB_FAIL(swap_tablet())) { LOG_WARN("failed to get alloc tablet handle", KR(ret)); diff --git a/src/storage/compaction/ob_basic_tablet_merge_ctx.h b/src/storage/compaction/ob_basic_tablet_merge_ctx.h index 00b7aae2c..6d8cd3832 100644 --- a/src/storage/compaction/ob_basic_tablet_merge_ctx.h +++ b/src/storage/compaction/ob_basic_tablet_merge_ctx.h @@ -204,7 +204,7 @@ public: int update_storage_schema_by_memtable( const ObStorageSchema &schema_on_tablet, const ObTablesHandleArray &merge_tables_handle); - static bool need_swap_tablet(const ObTablet &tablet, const int64_t row_count, const int64_t macro_count); + static bool need_swap_tablet(ObProtectedMemtableMgrHandle &memtable_mgr_handle, const int64_t row_count, const int64_t macro_count); VIRTUAL_TO_STRING_KV(K_(static_param), K_(static_desc), K_(parallel_merge_ctx), K_(tablet_handle), K_(info_collector), KP_(merge_dag)); protected: diff --git a/src/storage/compaction/ob_tenant_tablet_scheduler.cpp b/src/storage/compaction/ob_tenant_tablet_scheduler.cpp index b239b0ea5..a38ad618f 100644 --- a/src/storage/compaction/ob_tenant_tablet_scheduler.cpp +++ b/src/storage/compaction/ob_tenant_tablet_scheduler.cpp @@ -1022,6 +1022,7 @@ int ObTenantTabletScheduler::fill_minor_compaction_param( compaction_param.add_time_ = create_time; compaction_param.sstable_cnt_ = total_sstable_cnt; compaction_param.parallel_dag_cnt_ = parallel_dag_cnt; + ObProtectedMemtableMgrHandle *protected_handle = NULL; ObITable *table = nullptr; int64_t row_count = 0; @@ -1041,8 +1042,12 @@ int ObTenantTabletScheduler::fill_minor_compaction_param( } if (OB_SUCC(ret)) { - compaction_param.estimate_concurrent_count(MINOR_MERGE); - param.need_swap_tablet_flag_ = ObBasicTabletMergeCtx::need_swap_tablet(*tablet_handle.get_obj(), row_count, macro_count); + if (OB_FAIL(tablet_handle.get_obj()->get_protected_memtable_mgr_handle(protected_handle))) { + LOG_WARN("failed to get_protected_memtable_mgr_handle", K(ret), KPC(tablet_handle.get_obj())); + } else { + compaction_param.estimate_concurrent_count(MINOR_MERGE); + param.need_swap_tablet_flag_ = ObBasicTabletMergeCtx::need_swap_tablet(*protected_handle, row_count, macro_count); + } } return ret; } diff --git a/src/storage/ls/ob_freezer.cpp b/src/storage/ls/ob_freezer.cpp index 7c97bf494..2d288720d 100644 --- a/src/storage/ls/ob_freezer.cpp +++ b/src/storage/ls/ob_freezer.cpp @@ -794,7 +794,10 @@ int ObFreezer::tablet_freeze_with_rewrite_meta(const ObTabletID &tablet_id) } else if (OB_FAIL(protected_handle->set_is_tablet_freeze_for_active_memtable(frozen_memtable_handle))) { if (ret == OB_ENTRY_NOT_EXIST) { ret = OB_SUCCESS; - if (!tablet->has_memtable()) { + ObProtectedMemtableMgrHandle *protected_handle = NULL; + if (OB_FAIL(tablet->get_protected_memtable_mgr_handle(protected_handle))) { + LOG_WARN("failed to get_protected_memtable_mgr_handle", K(ret), KPC(tablet)); + } else if (!protected_handle->has_memtable()) { // We need trigger a dag to rewrite the snapshot version of tablet // meta for the major merge and medium merge. While the implementation // need pay much attentio. diff --git a/src/storage/meta_mem/ob_tablet_pointer_map.cpp b/src/storage/meta_mem/ob_tablet_pointer_map.cpp index 9763321b5..c056860ab 100644 --- a/src/storage/meta_mem/ob_tablet_pointer_map.cpp +++ b/src/storage/meta_mem/ob_tablet_pointer_map.cpp @@ -360,8 +360,6 @@ int ObTabletPointerMap::load_and_hook_meta_obj( } else { if (OB_FAIL(meta_pointer->hook_obj(t, guard))) { STORAGE_LOG(WARN, "fail to hook object", K(ret), KP(meta_pointer)); - } else if (OB_FAIL(guard.get_obj()->assign_pointer_handle(ptr_hdl))) { - STORAGE_LOG(WARN, "fail to assign pointer handle", K(ret)); } } } // write lock end @@ -411,6 +409,8 @@ int ObTabletPointerMap::load_meta_obj( } } else if (OB_FAIL(meta_pointer->read_from_disk(true/*is_full_load*/, arena_allocator, buf, buf_len, load_addr))) { STORAGE_LOG(WARN, "fail to read from disk", K(ret), KPC(meta_pointer)); + } else if (OB_FAIL(t->assign_pointer_handle(tmp_ptr_hdl))) { + STORAGE_LOG(WARN, "fail to assign pointer handle", K(ret), K(tmp_ptr_hdl)); } else { t->tablet_addr_ = load_addr; if (OB_FAIL(meta_pointer->deserialize(allocator, buf, buf_len, t))) { @@ -456,6 +456,8 @@ int ObTabletPointerMap::load_meta_obj( } } else if (OB_FAIL(meta_pointer->read_from_disk(false/*is_full_load*/, arena_allocator, buf, buf_len, load_addr))) { STORAGE_LOG(WARN, "fail to read from disk", K(ret), KPC(meta_pointer)); + } else if (OB_FAIL(t->assign_pointer_handle(tmp_ptr_hdl))) { + STORAGE_LOG(WARN, "fail to assign pointer handle", K(ret), K(tmp_ptr_hdl)); } else { t->tablet_addr_ = load_addr; if (OB_FAIL(meta_pointer->deserialize(buf, buf_len, t))) { @@ -551,8 +553,6 @@ int ObTabletPointerMap::get_meta_obj_with_external_memory( } } else if (OB_FAIL(t->deserialize_post_work(allocator))) { STORAGE_LOG(WARN, "fail to deserialize post work", K(ret), KP(t)); - } else if (OB_FAIL(t->assign_pointer_handle(ptr_hdl))) { - STORAGE_LOG(WARN, "fail to assign pointer handle", K(ret), KP(t)); } else { ObTenantMetaMemMgr *t3m = MTL(ObTenantMetaMemMgr*); guard.set_obj(t, &allocator, t3m); diff --git a/src/storage/tablet/ob_tablet.cpp b/src/storage/tablet/ob_tablet.cpp index 898d820aa..7afc77954 100644 --- a/src/storage/tablet/ob_tablet.cpp +++ b/src/storage/tablet/ob_tablet.cpp @@ -5699,6 +5699,7 @@ int ObTablet::set_memtable_clog_checkpoint_scn( ObTableHandleV2 handle; memtable::ObMemtable *memtable = nullptr; + ObProtectedMemtableMgrHandle *protected_handle = NULL; if (OB_UNLIKELY(!is_inited_)) { ret = OB_NOT_INIT; LOG_WARN("not inited", K(ret), K_(is_inited)); @@ -5707,7 +5708,9 @@ int ObTablet::set_memtable_clog_checkpoint_scn( } else if (tablet_meta->clog_checkpoint_scn_ <= tablet_meta_.clog_checkpoint_scn_) { // do nothing } else if (is_ls_inner_tablet()) { - if (OB_UNLIKELY(has_memtable())) { + if (OB_FAIL(get_protected_memtable_mgr_handle(protected_handle))) { + LOG_WARN("failed to get_protected_memtable_mgr_handle", K(ret), KPC(this)); + } else if (OB_UNLIKELY(protected_handle->has_memtable())) { ret = OB_ERR_UNEXPECTED; LOG_WARN("ls inner tablet should not have memtable", K(ret), KPC(tablet_meta)); } @@ -5965,7 +5968,10 @@ int ObTablet::pull_memtables_without_ddl() int ret = OB_SUCCESS; ObTableHandleArray memtable_handles; - if (!has_memtable()) { + ObProtectedMemtableMgrHandle *protected_handle = NULL; + if (OB_FAIL(get_protected_memtable_mgr_handle(protected_handle))) { + LOG_WARN("failed to get_protected_memtable_mgr_handle", K(ret), KPC(this)); + } else if (!protected_handle->has_memtable()) { LOG_TRACE("no memtable in memtable mgr", K(ret)); } else if (OB_FAIL(get_all_memtables(memtable_handles))) { LOG_WARN("failed to get all memtable", K(ret), KPC(this)); @@ -6059,7 +6065,10 @@ int ObTablet::update_memtables() int ret = OB_SUCCESS; ObTableHandleArray inc_memtables; - if (!has_memtable()) { + ObProtectedMemtableMgrHandle *protected_handle = NULL; + if (OB_FAIL(get_protected_memtable_mgr_handle(protected_handle))) { + LOG_WARN("failed to get_protected_memtable_mgr_handle", K(ret), KPC(this)); + } else if (!protected_handle->has_memtable()) { LOG_INFO("no memtable in memtable mgr", K(ret), "ls_id", tablet_meta_.ls_id_, "tablet_id", tablet_meta_.tablet_id_); } else if (OB_FAIL(get_all_memtables(inc_memtables))) { LOG_WARN("failed to get all memtable", K(ret), KPC(this)); @@ -7286,19 +7295,6 @@ int ObTablet::set_frozen_for_all_memtables() return ret; } -bool ObTablet::has_memtable() const -{ - bool ret = false; - int tmp_ret = OB_SUCCESS; - ObProtectedMemtableMgrHandle *protected_handle = NULL; - if (OB_TMP_FAIL(get_protected_memtable_mgr_handle(protected_handle))) { - LOG_WARN("failed to get_protected_memtable_mgr_handle", K(tmp_ret), KPC(this)); - } else { - ret = protected_handle->has_memtable(); - } - return ret; -} - int ObTablet::get_all_memtables(ObTableHdlArray &handle) const { int ret = OB_SUCCESS; diff --git a/src/storage/tablet/ob_tablet.h b/src/storage/tablet/ob_tablet.h index 7ff3ffcf7..e5f49de3f 100644 --- a/src/storage/tablet/ob_tablet.h +++ b/src/storage/tablet/ob_tablet.h @@ -372,7 +372,6 @@ public: int update_upper_trans_version(ObLS &ls, bool &is_updated); // memtable operation - bool has_memtable() const; int get_all_memtables(ObTableHdlArray &handle) const; int get_boundary_memtable(ObTableHandleV2 &handle) const; int get_protected_memtable_mgr_handle(ObProtectedMemtableMgrHandle *&handle) const;