diff --git a/be/src/clucene b/be/src/clucene index ace9ba07a880a0..75126ebce823d3 160000 --- a/be/src/clucene +++ b/be/src/clucene @@ -1 +1 @@ -Subproject commit ace9ba07a880a01d0161ee4a03418c30ba048fb9 +Subproject commit 75126ebce823d3c7a61396973330f132120a31ec diff --git a/be/src/olap/rowset/segment_v2/index_storage_format_v2.cpp b/be/src/olap/rowset/segment_v2/index_storage_format_v2.cpp index e9db5f2345564e..779d96c23987ba 100644 --- a/be/src/olap/rowset/segment_v2/index_storage_format_v2.cpp +++ b/be/src/olap/rowset/segment_v2/index_storage_format_v2.cpp @@ -187,8 +187,7 @@ IndexStorageFormatV2::create_output_stream() { DCHECK(_index_file_writer->_idx_v2_writer != nullptr) << "inverted index file writer v2 is nullptr"; - auto compound_file_output = std::unique_ptr( - out_dir->createOutputV2(_index_file_writer->_idx_v2_writer.get())); + auto compound_file_output = out_dir->createOutputV2(_index_file_writer->_idx_v2_writer.get()); return {std::move(out_dir_ptr), std::move(compound_file_output)}; } diff --git a/be/src/olap/rowset/segment_v2/inverted_index_fs_directory.cpp b/be/src/olap/rowset/segment_v2/inverted_index_fs_directory.cpp index 856c899943902a..4b397539d38d9d 100644 --- a/be/src/olap/rowset/segment_v2/inverted_index_fs_directory.cpp +++ b/be/src/olap/rowset/segment_v2/inverted_index_fs_directory.cpp @@ -693,9 +693,23 @@ lucene::store::IndexOutput* DorisFSDirectory::createOutput(const char* name) { return ret; } -lucene::store::IndexOutput* DorisFSDirectory::createOutputV2(io::FileWriter* file_writer) { - auto* ret = _CLNEW FSIndexOutputV2(); - ret->init(file_writer); +std::unique_ptr DorisFSDirectory::createOutputV2( + io::FileWriter* file_writer) { + auto ret = std::make_unique(); + ErrorContext error_context; + try { + ret->init(file_writer); + } catch (CLuceneError& err) { + error_context.eptr = std::current_exception(); + error_context.err_msg.append("FSIndexOutputV2 init error: "); + error_context.err_msg.append(err.what()); + LOG(ERROR) << error_context.err_msg; + } + FINALLY_EXCEPTION({ + if (error_context.eptr) { + FINALLY_CLOSE(ret); + } + }) return ret; } diff --git a/be/src/olap/rowset/segment_v2/inverted_index_fs_directory.h b/be/src/olap/rowset/segment_v2/inverted_index_fs_directory.h index 348db0bd297a45..f4704615fcdd47 100644 --- a/be/src/olap/rowset/segment_v2/inverted_index_fs_directory.h +++ b/be/src/olap/rowset/segment_v2/inverted_index_fs_directory.h @@ -79,7 +79,7 @@ class CLUCENE_EXPORT DorisFSDirectory : public lucene::store::Directory { void renameFile(const char* from, const char* to) override; void touchFile(const char* name) override; lucene::store::IndexOutput* createOutput(const char* name) override; - lucene::store::IndexOutput* createOutputV2(io::FileWriter* file_writer); + std::unique_ptr createOutputV2(io::FileWriter* file_writer); void close() override; std::string toString() const override; static const char* getClassName(); diff --git a/be/src/olap/rowset/segment_v2/inverted_index_searcher.cpp b/be/src/olap/rowset/segment_v2/inverted_index_searcher.cpp index 8d56b913b31c67..a8538dabab8756 100644 --- a/be/src/olap/rowset/segment_v2/inverted_index_searcher.cpp +++ b/be/src/olap/rowset/segment_v2/inverted_index_searcher.cpp @@ -21,6 +21,7 @@ #include #include "common/config.h" +#include "olap/rowset/segment_v2/inverted_index_common.h" #include "olap/rowset/segment_v2/inverted_index_compound_reader.h" #include "olap/rowset/segment_v2/inverted_index_desc.h" #include "olap/rowset/segment_v2/inverted_index_fs_directory.h" @@ -29,10 +30,10 @@ namespace doris::segment_v2 { Status FulltextIndexSearcherBuilder::build(lucene::store::Directory* directory, OptionalIndexSearcherPtr& output_searcher) { auto close_directory = true; - lucene::index::IndexReader* reader = nullptr; + std::unique_ptr reader; try { - reader = lucene::index::IndexReader::open( - directory, config::inverted_index_read_buffer_size, close_directory); + reader = std::unique_ptr(lucene::index::IndexReader::open( + directory, config::inverted_index_read_buffer_size, close_directory)); } catch (const CLuceneError& e) { std::vector file_names; directory->list(&file_names); @@ -44,16 +45,15 @@ Status FulltextIndexSearcherBuilder::build(lucene::store::Directory* directory, return Status::Error(msg); } bool close_reader = true; - auto index_searcher = std::make_shared(reader, close_reader); + reader_size = reader->getTermInfosRAMUsed(); + auto index_searcher = + std::make_shared(reader.release(), close_reader); if (!index_searcher) { output_searcher = std::nullopt; return Status::Error( "FulltextIndexSearcherBuilder build index_searcher error."); } - reader_size = reader->getTermInfosRAMUsed(); - // NOTE: need to cl_refcount-- here, so that directory will be deleted when - // index_searcher is destroyed - _CLDECDELETE(directory) + // NOTE: IndexSearcher takes ownership of the reader, and directory cleanup is handled by caller output_searcher = index_searcher; return Status::OK(); } @@ -69,7 +69,6 @@ Status BKDIndexSearcherBuilder::build(lucene::store::Directory* directory, } reader_size = bkd_reader->ram_bytes_used(); output_searcher = bkd_reader; - _CLDECDELETE(directory) return Status::OK(); } catch (const CLuceneError& e) { return Status::Error( @@ -104,13 +103,13 @@ Result> IndexSearcherBuilder::create_index Result IndexSearcherBuilder::get_index_searcher( lucene::store::Directory* directory) { OptionalIndexSearcherPtr result; - auto st = build(directory, result); + std::unique_ptr directory_ptr(directory); + + auto st = build(directory_ptr.get(), result); if (!st.ok()) { - _CLDECDELETE(directory) return ResultError(st); } if (!result.has_value()) { - _CLDECDELETE(directory) return ResultError(Status::Error( "InvertedIndexSearcherCache build error.")); } diff --git a/be/test/olap/rowset/segment_v2/inverted_index_fs_directory_test.cpp b/be/test/olap/rowset/segment_v2/inverted_index_fs_directory_test.cpp index ac47888ac33657..99ac4d34b41fbc 100644 --- a/be/test/olap/rowset/segment_v2/inverted_index_fs_directory_test.cpp +++ b/be/test/olap/rowset/segment_v2/inverted_index_fs_directory_test.cpp @@ -556,7 +556,7 @@ TEST_F(DorisFSDirectoryTest, FSIndexOutputV2FlushBufferError) { Status s = _fs->create_file(file_path, &writer); EXPECT_TRUE(s.ok()); - auto* output = _directory->createOutputV2(writer.get()); + auto output = _directory->createOutputV2(writer.get()); // Write small chunks to fill the buffer and trigger flush // BufferedIndexOutput buffer size is 1024 bytes @@ -573,7 +573,6 @@ TEST_F(DorisFSDirectoryTest, FSIndexOutputV2FlushBufferError) { } catch (...) { // Ignore close errors in cleanup } - delete output; } // Test 38: FSIndexOutputV2 flushBuffer with null writer diff --git a/conf/lsan_suppr.conf b/conf/lsan_suppr.conf index 953cad02f1c1a8..34de582ebe5a56 100644 --- a/conf/lsan_suppr.conf +++ b/conf/lsan_suppr.conf @@ -20,9 +20,3 @@ leak:brpc leak:libjvm leak:libzip leak:*_dl_map_object_deps* - -# Known leaks about index -leak:lucene::index::IndexReader::open -leak:lucene::index::IndexWriter::IndexWriter -leak:doris::segment_v2::IndexFileReader::open -leak:doris::segment_v2::IndexFileWriter::close