mrhhsg opened a new pull request, #71403:
URL: https://github.com/apache/doris/pull/71403

   ### Background
   
   Spill files consist of parts containing serialized blocks followed by block 
offsets, a maximum block size and a block count. Readers use that count to 
determine when a part is exhausted, including when merging sorted spill runs.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: None
   PR Type: Bugfix
   
   Problem Summary:
   
   A nonempty spill part whose block count is corrupted to zero can be silently 
skipped as an empty sorted run, producing incomplete query results. Validate 
zero-block footers in the shared reader and return an error identifying the 
part instead. Most of the diff adds focused unit coverage; valid empty and 
nonempty parts retain their existing behavior.
   
   ### Details
   
   - **Frequency:** Always when a zero-block declaration contradicts the part 
length or maximum block size; reproduced locally with a closed, nonempty spill 
part.
   - **Root cause:** `SpillFileReader::_read_footer` checked the block count 
upper bound but not the zero-count invariants. A zero count bypassed offset 
validation and let `read()` report normal exhaustion without consuming the 
existing data.
   - **Why existing tests missed it:** Reader round trips such as 
`ReadMultipleBlocks` and `PartRotationDataIntegrity` use valid writer output, 
while `GetBlockWithSpillError` injects a generic read failure rather than an 
inconsistent footer. The `sort_spill` and `window_function_spill` SQL suites 
exercise valid spill files, not this corruption.
   - **Fix:** Require a zero-block part to contain only the fixed tail and have 
a zero maximum block size. Reject either inconsistency with `INTERNAL_ERROR`, 
including the part path, length and maximum block size. This adds constant-time 
metadata comparisons without extra I/O or a format change.
   - **Other paths and branches:** Local and remote readers share this parser, 
including subsequent part opens and seek. Existing callers propagate its error, 
so no writer or sort-operator change is needed. Release branches were not 
evaluated; the introducing PR is unknown.
   - **Behavior change:** Inconsistent zero-block footers now fail instead of 
being silently skipped. Valid spill files keep the same format and behavior.
   
   ### Testing
   
   All runs below were local, using ASAN builds:
   
   - `SpillFileTest.NonemptyPartWithZeroBlockCountIsRejected`, 
`SpillFileTest.ZeroBlockFooterFieldConsistency` and 
`SpillSortSourceOperatorTest.GetBlockRejectsCorruptedZeroBlockFooter`: all 
three failed against the original parser because it returned OK for malformed 
footers, then all three passed with the fix.
   - `./run-be-ut.sh -j 16 --run 
--filter='SpillFileTest.*:SpillFileRemoteTest.*:SpillSortSourceOperatorTest.*'`:
 106 tests passed, with zero skips, covering reader behavior and sort-source 
error propagation. Remote tests use an in-memory filesystem fixture.
   - Existing `sort_spill` and `window_function_spill` SQL regression suites: 
both passed on one local BE, matching unchanged expected output.
   - No distributed corruption SQL or real-object-storage fault test was run.
   
   ### Release note
   
   Queries now report an error instead of silently skipping spill data when a 
nonempty spill part declares zero blocks.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details)
   - Does this need documentation: No
   - Pre-submission status: Ready
   
   ### AI Disclosure
   
   - Tool: Codex (model not stated).
   - Generated: Implementation, unit tests and this description.
   - Human review: Not stated.


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