From 8d6d93ee732f8077e16132d1986727e06da53e90 Mon Sep 17 00:00:00 2001 From: obdev Date: Fri, 9 Feb 2024 05:41:27 +0000 Subject: [PATCH] [CP] free a dup_tablet_set after 4013 --- src/storage/tx/ob_dup_table_tablets.cpp | 74 +++++++++++++++++-------- src/storage/tx/ob_dup_table_tablets.h | 5 +- 2 files changed, 52 insertions(+), 27 deletions(-) diff --git a/src/storage/tx/ob_dup_table_tablets.cpp b/src/storage/tx/ob_dup_table_tablets.cpp index 5f11ec2158..76d7b85d36 100644 --- a/src/storage/tx/ob_dup_table_tablets.cpp +++ b/src/storage/tx/ob_dup_table_tablets.cpp @@ -384,18 +384,8 @@ int ObLSDupTabletsMgr::init_free_tablet_pool_() const uint64_t tenant_id = MTL_ID(); for (int i = 0; i < RESERVED_FREE_SET_COUNT && OB_SUCC(ret); i++) { - DupTabletChangeMap *tmp_map_ptr = nullptr; - if (OB_ISNULL(tmp_map_ptr = static_cast( - share::mtl_malloc(sizeof(DupTabletChangeMap), "DupTabletMap")))) { - ret = OB_ALLOCATE_MEMORY_FAILED; - // } else if (OB_FALSE_IT(extra_free_set_alloc_count_++)) { - } else if (OB_FALSE_IT(new (tmp_map_ptr) DupTabletChangeMap(i + 1))) { - } else if (OB_FAIL(tmp_map_ptr->create(tenant_id, 1024))) { - DUP_TABLE_LOG(WARN, "create dup_tablet hash map", K(ret)); - } else if (false == (free_set_pool_.add_last(tmp_map_ptr))) { - ret = OB_ERR_UNEXPECTED; - DUP_TABLE_LOG(WARN, "push back into free_set_pool failed", K(ret), - K(free_set_pool_.get_size()), KPC(tmp_map_ptr)); + if (OB_FAIL(alloc_one_free_tablet_set_(i + 1))) { + DUP_TABLE_LOG(WARN, "alloc one free tablet set failed", K(ret), K(i)); } } @@ -2318,29 +2308,58 @@ int ObLSDupTabletsMgr::discover_dup_tablet_(const common::ObTabletID &tablet_id, K(readable_tablets_list_.get_size())); return ret; } -int ObLSDupTabletsMgr::alloc_extra_free_tablet_set_() + +int ObLSDupTabletsMgr::alloc_one_free_tablet_set_(const uint64_t uid) { int ret = OB_SUCCESS; + const int64_t origin_free_set_size = free_set_pool_.get_size(); + bool construct_object_succ = true; + DupTabletChangeMap *tmp_map_ptr = nullptr; const uint64_t tenant_id = MTL_ID(); + if (OB_ISNULL(tmp_map_ptr = static_cast( share::mtl_malloc(sizeof(DupTabletChangeMap), "DupTabletMap")))) { ret = OB_ALLOCATE_MEMORY_FAILED; - } else if (OB_FALSE_IT(extra_free_set_alloc_count_++)) { - } else if (OB_FALSE_IT(new (tmp_map_ptr) DupTabletChangeMap(RESERVED_FREE_SET_COUNT - + extra_free_set_alloc_count_))) { + DUP_TABLE_LOG(WARN, "alloc a dup tablet map failed", K(ret), K(uid), KPC(tmp_map_ptr)); + } else if (OB_FALSE_IT(new (tmp_map_ptr) DupTabletChangeMap(uid))) { + } else if (OB_FALSE_IT(construct_object_succ = true)) { } else if (OB_FAIL(tmp_map_ptr->create(tenant_id, 1024))) { DUP_TABLE_LOG(WARN, "create dup_tablet hash map", K(ret)); } else if (false == (free_set_pool_.add_last(tmp_map_ptr))) { - ret = OB_ERR_UNEXPECTED; + ret = OB_ALLOCATE_MEMORY_FAILED; DUP_TABLE_LOG(WARN, "push back into free_set_pool failed", K(ret), K(free_set_pool_.get_size()), KPC(tmp_map_ptr)); } - DUP_TABLE_LOG(INFO, "alloc a extra free tablet set", K(ret), K(last_no_free_set_time_), - K(extra_free_set_alloc_count_), KPC(changing_new_set_), - K(free_set_pool_.get_size()), K(need_confirm_new_queue_.get_size()), - K(readable_tablets_list_.get_size())); + + if (OB_FAIL(ret)) { + if (free_set_pool_.get_size() == origin_free_set_size) { + if (OB_NOT_NULL(tmp_map_ptr)) { + if (construct_object_succ) { + if (tmp_map_ptr->created()) { + tmp_map_ptr->destroy(); + } + tmp_map_ptr->~DupTabletChangeMap(); + } + + mtl_free(tmp_map_ptr); + } + + } else { + DUP_TABLE_LOG( + ERROR, "unexpected free set in hash_map, rewrite the err_code as OB_ERR_UNEXPECTED", + K(ret), KPC(tmp_map_ptr), K(origin_free_set_size), K(free_set_pool_.get_size())); + ret = OB_ERR_UNEXPECTED; + } + } else { + if (uid > RESERVED_FREE_SET_COUNT) { + DUP_TABLE_LOG(INFO, "alloc a extra free tablet set", K(ret), K(last_no_free_set_time_), + K(uid), K(extra_free_set_alloc_count_), KPC(changing_new_set_), + K(free_set_pool_.get_size()), K(need_confirm_new_queue_.get_size()), + K(readable_tablets_list_.get_size())); + } + } return ret; } @@ -2365,8 +2384,11 @@ int ObLSDupTabletsMgr::get_free_tablet_set(DupTabletChangeMap *&free_set, } while (OB_SUCC(ret) && target_id > RESERVED_FREE_SET_COUNT + extra_free_set_alloc_count_) { - if (OB_FAIL(alloc_extra_free_tablet_set_())) { + if (OB_FAIL( + alloc_one_free_tablet_set_(RESERVED_FREE_SET_COUNT + extra_free_set_alloc_count_ + 1))) { DUP_TABLE_LOG(WARN, "alloc extra free tablet set failed", K(ret)); + } else { + extra_free_set_alloc_count_++; } } @@ -2377,8 +2399,12 @@ int ObLSDupTabletsMgr::get_free_tablet_set(DupTabletChangeMap *&free_set, if (force_alloc || extra_free_set_alloc_count_ < MAX_FREE_SET_COUNT - RESERVED_FREE_SET_COUNT || ObTimeUtility::fast_current_time() - last_no_free_set_time_ >= 3 * 1000 * 1000) { - if (OB_FAIL(alloc_extra_free_tablet_set_())) { - DUP_TABLE_LOG(WARN, "alloc extra free tablet set failed", K(ret)); + if (OB_FAIL(alloc_one_free_tablet_set_(RESERVED_FREE_SET_COUNT + extra_free_set_alloc_count_ + + 1))) { + DUP_TABLE_LOG(WARN, "alloc extra free tablet set failed", K(ret), + K(RESERVED_FREE_SET_COUNT), K(extra_free_set_alloc_count_)); + } else { + extra_free_set_alloc_count_++; } } } diff --git a/src/storage/tx/ob_dup_table_tablets.h b/src/storage/tx/ob_dup_table_tablets.h index 50b706c9ad..07839649c5 100644 --- a/src/storage/tx/ob_dup_table_tablets.h +++ b/src/storage/tx/ob_dup_table_tablets.h @@ -807,9 +807,8 @@ private: int init_free_tablet_pool_(); int destroy_free_tablet_pool_(); - // int get_changing_new_set_(DupTabletChangeMap *&changing_new_set); - // int get_old_tablet_set_(DupTabletChangeMap *&old_tablet_set); - int alloc_extra_free_tablet_set_(); + int alloc_one_free_tablet_set_(const uint64_t uid); + int get_free_tablet_set(DupTabletChangeMap *&free_set, const bool force_alloc = false, const uint64_t target_id = 0);