liaoxin01 commented on code in PR #62342:
URL: https://github.com/apache/doris/pull/62342#discussion_r3063513244
##########
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:
I did not add a V1 filename test because V1 inverted-index tablets never
enable PackedFileSystem in the first place, so that naming pattern is not an
input to this helper. I pushed b0ceb175026 to clarify the V2-only assumption in
the code comment.
##########
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:
Thanks. This helper only runs when PackedFileSystem is enabled. V1
inverted-index tablets are excluded before that in
be/src/storage/rowset/rowset_writer_context.h, where packed_file_active is
forced off for V1. Also be/src/storage/rowset/rowset_writer.h only routes V2
index files through create_file_writer(..., INVERTED_INDEX_FILE); V1 does not
use this packed-file path. So the V1 filename form does not reach
should_use_packed_writer(). I pushed b0ceb175026 to clarify that in the comment.
--
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]