Copilot commented on code in PR #62342:
URL: https://github.com/apache/doris/pull/62342#discussion_r3063470834
##########
be/src/io/fs/packed_file_system.cpp:
##########
@@ -26,6 +27,39 @@
namespace doris::io {
+namespace {
+
+// Only keep packed-file aggregation for the first segment in a rowset.
+// The path handled here is expected to look like:
+// local/remote segment file: .../{rowset_id}_{segment_id}.dat
+// local/remote index file: .../{rowset_id}_{segment_id}.idx
+// Multi-segment rowsets usually come from large loads or memory-pressure
flushes,
+// and continuing to buffer later segments in packed files can amplify memory
usage.
+// Non-rowset file names keep the legacy behavior to avoid changing unrelated
callers.
+bool should_use_packed_writer(std::string_view file_name) {
+ constexpr std::string_view kSegmentSuffix = ".dat";
+ constexpr std::string_view kIndexSuffix = ".idx";
+
+ size_t suffix_len = 0;
+ if (file_name.ends_with(kSegmentSuffix)) {
+ suffix_len = kSegmentSuffix.size();
+ } else if (file_name.ends_with(kIndexSuffix)) {
+ suffix_len = kIndexSuffix.size();
+ } else {
+ return true;
+ }
+
+ file_name.remove_suffix(suffix_len);
+ size_t pos = file_name.rfind('_');
+ if (pos == std::string_view::npos || pos + 1 >= file_name.size()) {
+ return true;
+ }
+
+ return file_name.substr(pos + 1) == "0";
+}
Review Comment:
`should_use_packed_writer()` assumes index files are named
`{rowset_id}_{segment_id}.idx`, but the codebase also has V1 inverted-index
filenames like `{rowset_id}_{seg_id}_{index_id}@{suffix}.idx` (see
`InvertedIndexDescriptor::get_index_file_name_v1`). With the current
`rfind('_')` logic, the function ends up comparing the *index_id*@suffix (or
index_id) to "0", so segment 0 index files will usually bypass packed files and
later-segment index files may be misclassified. Consider parsing segment_id by
stripping the known `append_info.rowset_id + '_'` prefix (available in
`PackedFileSystem::_append_info`) and then reading the first numeric token as
`seg_id` for both V1 and V2 idx formats (and `.dat`).
##########
be/test/io/fs/packed_file_system_test.cpp:
##########
@@ -233,6 +233,57 @@ TEST_F(PackedFileSystemTest,
CreateFileWrapsWithPackedFileWriter) {
EXPECT_TRUE(st.ok());
}
+TEST_F(PackedFileSystemTest, FirstSegmentDataFileUsesPackedWriter) {
+ PackedFileSystem merge_fs(_inner_fs, _append_info);
+
+ Path file_path("rowset_1_0.dat");
+ FileWriterPtr writer;
+ ASSERT_TRUE(merge_fs.create_file(file_path, &writer, nullptr).ok());
+ ASSERT_NE(writer, nullptr);
+
+ std::string data = "test";
+ Slice slice(data);
+ ASSERT_TRUE(writer->appendv(&slice, 1).ok());
+
+ ASSERT_NE(_inner_fs->last_writer(), nullptr);
+ EXPECT_EQ(_inner_fs->last_writer()->bytes_appended(), 0);
+ EXPECT_TRUE(writer->is_in_packed_file());
+}
+
+TEST_F(PackedFileSystemTest, LaterSegmentDataFileUsesDirectWriter) {
+ PackedFileSystem merge_fs(_inner_fs, _append_info);
+
+ Path file_path("rowset_1_1.dat");
+ FileWriterPtr writer;
+ ASSERT_TRUE(merge_fs.create_file(file_path, &writer, nullptr).ok());
+ ASSERT_NE(writer, nullptr);
+
+ std::string data = "test";
+ Slice slice(data);
+ ASSERT_TRUE(writer->appendv(&slice, 1).ok());
+
+ ASSERT_NE(_inner_fs->last_writer(), nullptr);
+ EXPECT_EQ(_inner_fs->last_writer()->bytes_appended(), data.size());
+ EXPECT_FALSE(writer->is_in_packed_file());
+}
+
+TEST_F(PackedFileSystemTest, LaterSegmentIndexFileUsesDirectWriter) {
+ PackedFileSystem merge_fs(_inner_fs, _append_info);
+
+ Path file_path("rowset_1_2.idx");
+ FileWriterPtr writer;
+ ASSERT_TRUE(merge_fs.create_file(file_path, &writer, nullptr).ok());
+ ASSERT_NE(writer, nullptr);
+
+ std::string data = "idx";
+ Slice slice(data);
+ ASSERT_TRUE(writer->appendv(&slice, 1).ok());
+
+ ASSERT_NE(_inner_fs->last_writer(), nullptr);
+ EXPECT_EQ(_inner_fs->last_writer()->bytes_appended(), data.size());
+ EXPECT_FALSE(writer->is_in_packed_file());
+}
+
Review Comment:
The new tests cover `.dat` (seg 0 vs seg 1) and a V2-style `.idx` name
(`{rowset_id}_{seg}.idx`), but they don't cover the V1 inverted-index filename
format `{rowset_id}_{seg_id}_{index_id}@{suffix}.idx`. Since
`should_use_packed_writer()` now branches on `.idx` too, adding a test with a
V1-style index filename would prevent regressions and would catch the current
parsing issue.
```suggestion
TEST_F(PackedFileSystemTest, V1InvertedIndexFileUsesDirectWriter) {
PackedFileSystem merge_fs(_inner_fs, _append_info);
Path file_path("[email protected]");
FileWriterPtr writer;
ASSERT_TRUE(merge_fs.create_file(file_path, &writer, nullptr).ok());
ASSERT_NE(writer, nullptr);
std::string data = "v1_idx";
Slice slice(data);
ASSERT_TRUE(writer->appendv(&slice, 1).ok());
ASSERT_NE(_inner_fs->last_writer(), nullptr);
EXPECT_EQ(_inner_fs->last_writer()->bytes_appended(), data.size());
EXPECT_FALSE(writer->is_in_packed_file());
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]