@@ -39,7 +39,6 @@ IndexStorageFormatV2::IndexStorageFormatV2(IndexFileWriter* index_file_writer)
3939 : IndexStorageFormat(index_file_writer) {}
4040
4141Status IndexStorageFormatV2::write () {
42- std::unique_ptr<lucene::store::Directory, DirectoryDeleter> out_dir = nullptr ;
4342 std::unique_ptr<lucene::store::IndexOutput> compound_file_output = nullptr ;
4443 ErrorContext error_context;
4544 try {
@@ -48,11 +47,13 @@ Status IndexStorageFormatV2::write() {
4847 // Prepare file metadata
4948 auto file_metadata = prepare_file_metadata (current_offset);
5049
51- // Create output stream
52- auto result = create_output_stream ();
53- out_dir = std::move (result.first );
54- compound_file_output = std::move (result.second );
55- VLOG_DEBUG << fmt::format (" Output compound index file to streams: {}" , out_dir->toString ());
50+ // Create output stream directly without directory operations.
51+ // This is important for cloud storage (like S3) where directory operations are not
52+ // supported or unnecessary.
53+ compound_file_output = create_output_stream ();
54+ auto index_path = InvertedIndexDescriptor::get_index_file_path_v2 (
55+ _index_file_writer->_index_path_prefix );
56+ VLOG_DEBUG << fmt::format (" Output compound index file to: {}" , index_path);
5657
5758 // Write version and number of indices
5859 write_version_and_indices_count (compound_file_output.get ());
@@ -75,10 +76,7 @@ Status IndexStorageFormatV2::write() {
7576 error_context.err_msg .append (err.what ());
7677 LOG (ERROR) << error_context.err_msg ;
7778 }
78- FINALLY ({
79- FINALLY_CLOSE (compound_file_output);
80- FINALLY_CLOSE (out_dir);
81- })
79+ FINALLY ({ FINALLY_CLOSE (compound_file_output); })
8280
8381 return Status::OK ();
8482}
@@ -177,21 +175,16 @@ std::vector<FileMetadata> IndexStorageFormatV2::prepare_file_metadata(int64_t& c
177175 return file_metadata;
178176}
179177
180- std::pair<std::unique_ptr<lucene::store::Directory, DirectoryDeleter>,
181- std::unique_ptr<lucene::store::IndexOutput>>
182- IndexStorageFormatV2::create_output_stream () {
183- io::Path index_path {InvertedIndexDescriptor::get_index_file_path_v2 (
184- _index_file_writer->_index_path_prefix )};
185-
186- auto * out_dir = DorisFSDirectoryFactory::getDirectory (_index_file_writer->_fs ,
187- index_path.parent_path ().c_str ());
188- out_dir->set_file_writer_opts (_index_file_writer->_opts );
189- std::unique_ptr<lucene::store::Directory, DirectoryDeleter> out_dir_ptr (out_dir);
190-
178+ std::unique_ptr<lucene::store::IndexOutput> IndexStorageFormatV2::create_output_stream () {
179+ // For V2 format, we create the output stream directly using the file writer,
180+ // bypassing the directory layer entirely. This optimization is especially important
181+ // for cloud storage (like S3) where:
182+ // 1. Directory operations (exists, create_directory) are unnecessary overhead
183+ // 2. S3 doesn't have a real directory concept - directories are just key prefixes
184+ // 3. The file writer is already created and ready to use
191185 DCHECK (_index_file_writer->_idx_v2_writer != nullptr )
192186 << " inverted index file writer v2 is nullptr" ;
193- auto compound_file_output = out_dir->createOutputV2 (_index_file_writer->_idx_v2_writer .get ());
194- return {std::move (out_dir_ptr), std::move (compound_file_output)};
187+ return DorisFSDirectory::FSIndexOutputV2::create (_index_file_writer->_idx_v2_writer .get ());
195188}
196189
197190void IndexStorageFormatV2::write_version_and_indices_count (lucene::store::IndexOutput* output) {
0 commit comments