From 7150d3c5aa8f5b8ba54e6c292ec44dfa9e7d3fa2 Mon Sep 17 00:00:00 2001 From: Xu Peng Date: Wed, 24 Apr 2019 15:42:08 +0800 Subject: [PATCH] feat(db): cache for index Former-commit-id: e33cb100824e8714e539bec4f6622753001a9606 --- cpp/src/db/DBImpl.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cpp/src/db/DBImpl.cpp b/cpp/src/db/DBImpl.cpp index 0cd976cc..2115c637 100644 --- a/cpp/src/db/DBImpl.cpp +++ b/cpp/src/db/DBImpl.cpp @@ -239,7 +239,6 @@ Status DBImpl::merge_files(const std::string& group_id, const meta::DateT& date, LOG(DEBUG) << "New merged file " << group_file.file_id << " of size=" << group_file.rows; - /* auto to_cache = zilliz::vecwise::cache::DataObj(std::make_shared(index)); */ zilliz::vecwise::cache::CpuCacheMgr::GetInstance()->InsertItem( group_file.location, std::make_shared(index)); @@ -289,7 +288,12 @@ Status DBImpl::build_index(const meta::GroupFileSchema& file) { opd->index_type = "IDMap,Flat"; IndexBuilderPtr pBuilder = GetIndexBuilder(opd); - auto from_index = dynamic_cast(faiss::read_index(file.location.c_str())); + auto to_index = zilliz::vecwise::cache::CpuCacheMgr::GetInstance()->GetIndex(file.location); + if (!to_index) { + to_index = read_index(file.location.c_str()); + } + auto from_index = dynamic_cast(to_index->data().get()); + LOG(DEBUG) << "Preparing build_index for file_id=" << file.file_id << " with new index_file_id=" << group_file.file_id << std::endl; auto index = pBuilder->build_all(from_index->ntotal, @@ -308,7 +312,8 @@ Status DBImpl::build_index(const meta::GroupFileSchema& file) { meta::GroupFilesSchema update_files = {to_remove, group_file}; _pMeta->update_files(update_files); - delete from_index; + zilliz::vecwise::cache::CpuCacheMgr::GetInstance()->InsertItem(group_file.location, index); + return Status::OK(); } -- GitLab