hello-stephen commented on code in PR #71403:
URL: https://github.com/apache/doris/pull/71403#discussion_r4791288055


##########
be/src/exec/spill/spill_file_reader.cpp:
##########
@@ -147,6 +147,14 @@ Status SpillFileReader::_read_footer(size_t file_size, 
bool fetch_small_part) {
         return Status::InternalError("spill part {} of {} bytes has a 
corrupted block count {}",
                                      _file_reader->path().native(), file_size, 
_part_block_count);
     }
+    // A zero-block part contains only the tail and has a zero max block size. 
Otherwise,
+    // a corrupted count could make the reader silently skip a nonempty part 
as an empty run.
+    if (_part_block_count == 0 &&
+        (file_size != kFooterTailBytes || _part_max_sub_block_size != 0)) {
+        return Status::InternalError(

Review Comment:
   [P2] Preserve Iceberg output cleanup when a later spill part fails 
validation. In a sorted Iceberg write, a valid first part lets the merger 
initialize and write rows. If a later part hits this check, the spill supplier 
error throws out of `VSortedRunMerger::get_next()`. The close guard in 
`VIcebergSortWriter::close()` sets `_closed` before `_close_locked()` can 
forward the failure to the partition writer. The scheduler fails the write and 
retries cleanup, but the closed sorter skips the active file. The Parquet 
stream can still publish that file during destruction, leaving an S3 object 
whose path neither the BE nor the FE has recorded for rollback. Convert the 
merge exception to a failed `Status` before leaving the sort writer’s close 
path so partition cleanup runs.



##########
be/test/vec/spill/spill_file_test.cpp:
##########
@@ -489,6 +493,128 @@ TEST_F(SpillFileTest, ReadSingleBlock) {
     ASSERT_TRUE(st.ok());
 }
 
+TEST_F(SpillFileTest, NonemptyPartWithZeroBlockCountIsRejected) {
+    auto spill_file = std::make_shared<SpillFile>(_data_dir_ptr, 
"test_query/zero_block_count");
+    SpillFileWriterSPtr writer;
+    auto st = spill_file->create_writer(_runtime_state.get(), _profile.get(), 
writer);
+    ASSERT_TRUE(st.ok()) << st;
+    for (int i = 0; i < 3; ++i) {
+        std::vector<int32_t> values(100);
+        std::iota(values.begin(), values.end(), i * 100);
+        auto block = _create_int_block(values);
+        st = writer->write_block(_runtime_state.get(), block);
+        ASSERT_TRUE(st.ok()) << st;
+    }
+    st = writer->close();
+    ASSERT_TRUE(st.ok()) << st;
+    writer.reset();
+
+    auto baseline = spill_file->create_reader(_runtime_state.get(), 
_profile.get());
+    st = baseline->open();
+    ASSERT_TRUE(st.ok()) << st;
+    size_t rows = 0;
+    int64_t sum = 0;
+    bool eos = false;
+    while (!eos) {
+        Block block;
+        st = baseline->read(&block, &eos);
+        ASSERT_TRUE(st.ok()) << st;
+        rows += block.rows();
+        for (size_t row = 0; row < block.rows(); ++row) {
+            sum += block.get_by_position(0).column->get_int(row);
+        }
+    }
+    ASSERT_EQ(rows, 300);
+    ASSERT_EQ(sum, 44850);
+    st = baseline->close();
+    ASSERT_TRUE(st.ok()) << st;
+
+    const auto part_path = 
std::filesystem::path(_data_dir_ptr->get_spill_data_path()) /
+                           "test_query/zero_block_count/0";
+    std::ifstream original_input(part_path, std::ios::binary);
+    ASSERT_TRUE(original_input.is_open());
+    const std::string 
original((std::istreambuf_iterator<char>(original_input)),
+                               std::istreambuf_iterator<char>());
+    original_input.close();
+    ASSERT_GT(original.size(), 5 * sizeof(size_t));
+    size_t original_count = 0;
+    size_t original_max = 0;
+    memcpy(&original_count, original.data() + original.size() - 
sizeof(size_t), sizeof(size_t));
+    memcpy(&original_max, original.data() + original.size() - 2 * 
sizeof(size_t), sizeof(size_t));
+    ASSERT_EQ(original_count, 3);

Review Comment:
   [P3] Make the three-block test fixture independent of the configured part 
limit. The BE test runner loads `be.conf`, and `SpillFileWriter` rotates parts 
at `spill_file_part_size_bytes`. A small limit can put the three writes in 
separate parts, so the 300-row control passes but this assertion fails before 
the test corrupts the footer. Set and restore a part limit large enough to keep 
all three blocks in the first part.



-- 
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]

Reply via email to