[fix] ivf calc center id core cause by ivf center id cache heap use after free

This commit is contained in:
884244693
2025-02-08 04:18:49 +00:00
committed by ob-robot
parent 29dd4290e6
commit 1accfeb110
2 changed files with 13 additions and 8 deletions

View File

@ -2697,7 +2697,7 @@ ObExprVecIvfCenterIdCache* ObVectorIndexUtil::get_ivf_center_id_cache_ctx(const
void *cache_ctx_buf = NULL;
ret = exec_ctx->create_expr_op_ctx(id, sizeof(ObExprVecIvfCenterIdCtx), cache_ctx_buf);
if (OB_SUCC(ret) && OB_NOT_NULL(cache_ctx_buf)) {
cache_ctx = new (cache_ctx_buf) ObExprVecIvfCenterIdCtx(exec_ctx->get_allocator());
cache_ctx = new (cache_ctx_buf) ObExprVecIvfCenterIdCtx();
}
}
}
@ -2715,7 +2715,7 @@ void ObVectorIndexUtil::get_ivf_pq_center_id_cache_ctx(const uint64_t& id, sql::
void *cache_ctx_buf = NULL;
ret = exec_ctx->create_expr_op_ctx(id, sizeof(ObExprVecIvfCenterIdCtx), cache_ctx_buf);
if (OB_SUCC(ret) && OB_NOT_NULL(cache_ctx_buf)) {
cache_ctx = new (cache_ctx_buf) ObExprVecIvfCenterIdCtx(exec_ctx->get_allocator());
cache_ctx = new (cache_ctx_buf) ObExprVecIvfCenterIdCtx();
}
}
}
@ -2747,7 +2747,8 @@ int ObVectorIndexUtil::get_ivf_aux_info(share::ObPluginVectorIndexService *servi
LOG_WARN("failed to get centers from cache", K(ret));
}
} else {
if (OB_FAIL(service->get_ivf_aux_info(table_id, tablet_id, allocator, centers))) {
cache->reuse();
if (OB_FAIL(service->get_ivf_aux_info(table_id, tablet_id, cache->get_allocator(), centers))) {
LOG_WARN("failed to get centers", K(ret));
} else if (OB_FAIL(cache->update_cache(table_id, tablet_id, centers))) {
LOG_WARN("failed to update ivf center id cache", K(ret));

View File

@ -122,10 +122,11 @@ public:
class ObExprVecIvfCenterIdCache
{
public:
ObExprVecIvfCenterIdCache(common::ObIAllocator &allocator)
ObExprVecIvfCenterIdCache()
: table_id_(ObCommonID::INVALID_ID),
tablet_id_(),
centers_()
centers_(),
allocator_("IvfCIdCache", OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID())
{}
virtual ~ObExprVecIvfCenterIdCache() {}
bool hit(ObTableID table_id, ObTabletID tablet_id) { return table_id == table_id_ && tablet_id == tablet_id_; }
@ -136,10 +137,13 @@ public:
tablet_id_ = tablet_id;
return centers_.assign(centers);
}
ObArenaAllocator &get_allocator() { return allocator_; }
void reuse() { table_id_ = ObCommonID::INVALID_ID; tablet_id_.reset(); centers_.reuse(); allocator_.reuse(); }
private:
ObTableID table_id_;
ObTabletID tablet_id_;
ObSEArray<float*, 8> centers_;
ObArenaAllocator allocator_;
};
class ObVectorIndexUtil final
@ -147,10 +151,10 @@ class ObVectorIndexUtil final
class ObExprVecIvfCenterIdCtx : public sql::ObExprOperatorCtx
{
public:
ObExprVecIvfCenterIdCtx(common::ObIAllocator &allocator)
ObExprVecIvfCenterIdCtx()
: ObExprOperatorCtx(),
cache_(allocator),
pq_cache_(allocator)
cache_(),
pq_cache_()
{}
virtual ~ObExprVecIvfCenterIdCtx() {}
ObExprVecIvfCenterIdCache *get_cache() { return &cache_; }