From dcaea1a9106b51143e26b9fcd4af9d4bee5a8c96 Mon Sep 17 00:00:00 2001 From: luzhang Date: Tue, 10 Dec 2024 23:27:49 +0800 Subject: [PATCH] fix:fix incorrect dir operations when create or load inverted index Signed-off-by: luzhang --- .../core/src/index/InvertedIndexTantivy.cpp | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/internal/core/src/index/InvertedIndexTantivy.cpp b/internal/core/src/index/InvertedIndexTantivy.cpp index 663564dd95b23..93ca21e3140fa 100644 --- a/internal/core/src/index/InvertedIndexTantivy.cpp +++ b/internal/core/src/index/InvertedIndexTantivy.cpp @@ -76,20 +76,6 @@ InvertedIndexTantivy::InvertedIndexTantivy( schema_(ctx.fieldDataMeta.field_schema) { mem_file_manager_ = std::make_shared(ctx); disk_file_manager_ = std::make_shared(ctx); - auto field = - std::to_string(disk_file_manager_->GetFieldDataMeta().field_id); - auto prefix = disk_file_manager_->GetIndexIdentifier(); - path_ = std::string(TMP_INVERTED_INDEX_PREFIX) + prefix; - boost::filesystem::create_directories(path_); - d_type_ = get_tantivy_data_type(schema_); - if (tantivy_index_exist(path_.c_str())) { - LOG_INFO( - "index {} already exists, which should happen in loading progress", - path_); - } else { - wrapper_ = std::make_shared( - field.c_str(), d_type_, path_.c_str()); - } } template @@ -97,6 +83,7 @@ InvertedIndexTantivy::~InvertedIndexTantivy() { auto local_chunk_manager = storage::LocalChunkManagerSingleton::GetInstance().GetChunkManager(); auto prefix = path_; + LOG_INFO("Inverted index remove path:{}", path_); local_chunk_manager->RemoveDir(prefix); } @@ -214,6 +201,7 @@ InvertedIndexTantivy::Load(milvus::tracer::TraceContext ctx, (size_t)index_valid_data->size); } disk_file_manager_->CacheIndexToDisk(files_value); + path_ = prefix; wrapper_ = std::make_shared(prefix.c_str()); } @@ -420,6 +408,15 @@ template void InvertedIndexTantivy::BuildWithFieldData( const std::vector>& field_datas) { + auto field = + std::to_string(disk_file_manager_->GetFieldDataMeta().field_id); + auto prefix = disk_file_manager_->GetIndexIdentifier(); + path_ = std::string(TMP_INVERTED_INDEX_PREFIX) + prefix; + boost::filesystem::create_directories(path_); + d_type_ = get_tantivy_data_type(schema_); + wrapper_ = std::make_shared( + field.c_str(), d_type_, path_.c_str()); + if (schema_.nullable()) { int64_t total = 0; for (const auto& data : field_datas) {