From 934868deea2ff6358be183dc01c27c5757b05b35 Mon Sep 17 00:00:00 2001 From: wu-xingying <729224612@qq.com> Date: Mon, 28 Oct 2024 03:44:11 +0000 Subject: [PATCH] [CP] adaptor iter use after free core dump --- src/share/vector_index/ob_plugin_vector_index_adaptor.cpp | 7 +++++-- src/share/vector_index/ob_plugin_vector_index_adaptor.h | 4 +++- src/share/vector_index/ob_plugin_vector_index_util.cpp | 3 --- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/share/vector_index/ob_plugin_vector_index_adaptor.cpp b/src/share/vector_index/ob_plugin_vector_index_adaptor.cpp index 95a37ee7c..c6086f881 100644 --- a/src/share/vector_index/ob_plugin_vector_index_adaptor.cpp +++ b/src/share/vector_index/ob_plugin_vector_index_adaptor.cpp @@ -279,7 +279,7 @@ ObPluginVectorIndexAdaptor::ObPluginVectorIndexAdaptor(common::ObIAllocator *all inc_table_id_(OB_INVALID_ID), vbitmap_table_id_(OB_INVALID_ID), snapshot_table_id_(OB_INVALID_ID), data_table_id_(OB_INVALID_ID), rowkey_vid_table_id_(OB_INVALID_ID), vid_rowkey_table_id_(OB_INVALID_ID), - ref_cnt_(0), idle_cnt_(0), mem_check_cnt_(0), all_vsag_use_mem_(nullptr), allocator_(allocator), + ref_cnt_(0), idle_cnt_(0), mem_check_cnt_(0), is_mem_limited_(false), all_vsag_use_mem_(nullptr), allocator_(allocator), parent_mem_ctx_(entity), index_identity_(), follower_sync_statistics_() { } @@ -935,6 +935,8 @@ int ObPluginVectorIndexAdaptor::add_snap_index(float *vectors, int64_t *vids, in } else if (OB_ISNULL(vids)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("get invalid data.", K(ret)); + } else if (OB_FAIL(check_vsag_mem_used())) { + LOG_WARN("check vsag mem used failed.", K(ret)); } else { lib::ObMallocHookAttrGuard malloc_guard(lib::ObMemAttr(tenant_id_, "VIndexVsagADP")); TCWLockGuard lock_guard(snap_data_->mem_data_rwlock_); @@ -2167,7 +2169,7 @@ int ObPluginVectorIndexAdaptor::check_vsag_mem_used() // because mem_check_cnt_ is used to roughly determine // whether to perform memory verification and does not require accurate counting. mem_check_cnt_++; - if (mem_check_cnt_ % 10 == 0) { + if (is_mem_limited_ || mem_check_cnt_ % 10 == 0) { mem_check_cnt_ %= 10; ObRbMemMgr *mem_mgr = nullptr; int64_t bitmap_mem_used = 0; @@ -2179,6 +2181,7 @@ int ObPluginVectorIndexAdaptor::check_vsag_mem_used() if (OB_FAIL(ObPluginVectorIndexHelper::get_vector_memory_limit_size(tenant_id_, mem_size))) { LOG_WARN("failed to get vector mem limit size.", K(ret), K(tenant_id_)); } else if (ATOMIC_LOAD(all_vsag_use_mem_) + bitmap_mem_used > mem_size) { + is_mem_limited_ = true; ret = OB_ERR_VSAG_MEM_LIMIT_EXCEEDED; LOG_USER_ERROR(OB_ERR_VSAG_MEM_LIMIT_EXCEEDED, int(mem_size>>20)); LOG_WARN("Memory usage exceeds user limit.", K(ret), K(mem_size), K(ATOMIC_LOAD(all_vsag_use_mem_)), K(bitmap_mem_used)); diff --git a/src/share/vector_index/ob_plugin_vector_index_adaptor.h b/src/share/vector_index/ob_plugin_vector_index_adaptor.h index d20c9f2a3..4de9122eb 100644 --- a/src/share/vector_index/ob_plugin_vector_index_adaptor.h +++ b/src/share/vector_index/ob_plugin_vector_index_adaptor.h @@ -503,7 +503,8 @@ public: K_(data_table_id), K_(rowkey_vid_table_id), K_(vid_rowkey_table_id), K_(inc_table_id), K_(vbitmap_table_id), K_(snapshot_table_id), K_(ref_cnt), K_(idle_cnt), KP_(allocator), - K_(index_identity), K_(follower_sync_statistics)); + K_(index_identity), K_(follower_sync_statistics), + K_(mem_check_cnt), K_(is_mem_limited)); private: void *get_incr_index(); @@ -566,6 +567,7 @@ private: int64_t ref_cnt_; int64_t idle_cnt_; // not merged cnt int64_t mem_check_cnt_; + bool is_mem_limited_; uint64_t *all_vsag_use_mem_; ObIAllocator *allocator_; // allocator for alloc adapter self lib::MemoryContext &parent_mem_ctx_; diff --git a/src/share/vector_index/ob_plugin_vector_index_util.cpp b/src/share/vector_index/ob_plugin_vector_index_util.cpp index 4dc7c65db..5388190fd 100644 --- a/src/share/vector_index/ob_plugin_vector_index_util.cpp +++ b/src/share/vector_index/ob_plugin_vector_index_util.cpp @@ -123,9 +123,6 @@ void ObVectorQueryVidIterator::reset() is_init_ = false; total_ = 0; cur_pos_ = 0; - if (OB_NOT_NULL(allocator_)) { - allocator_->reset(); - } } int ObPluginVectorIndexHelper::merge_delta_and_snap_vids(const ObVsagQueryResult &first,