Davis-Zhang-Onehouse opened a new pull request, #20787:
URL: https://github.com/apache/hudi/pull/20787

   ### Describe the issue this Pull Request addresses
   
   issue: #20786
   Part of #20683, RFC-118 (#20684).
   Stacked on #20688: review only the last commit. Until the PRs below it 
merge, this PR also shows their commits.
   
   In a merge-on-read Spark read, `HoodieFileGroupReaderFunction` opens the 
file group reader and then builds the projected rows over it. If that step 
fails (for example while loading the log files after the base file is open, or 
in a projection's code generation), no task listener holds the reader yet, so 
the open base file is never closed.
   
   `SerializableIndexedRecord` keeps the Avro encoding of a decoded record 
after the first encode. A buffer of decoded records being serialized (a Spark 
shuffle spill writing out its map) then holds each payload twice, beyond the 
size Spark accounted for, and a record changed after one serialization 
serializes stale bytes. Its Java deserialization reads the record bytes with a 
single `read` call, which can return fewer bytes than requested for a large 
record.
   
   ### Summary and Changelog
   
   A failed MOR read closes the file it opened, and serializing decoded records 
keeps one copy of each payload and carries later updates.
   
   - `HoodieFileGroupReaderFunction.closeOnFailure` wraps the row-building 
step: on failure it closes the file group reader and rethrows the original 
failure, with a close failure added as suppressed (through 
`CloseableUtils.closeSuppressing`).
   - `SerializableIndexedRecord.encodeRecord` returns the bytes a still-encoded 
record was read from, and encodes a decoded record on each call without keeping 
the bytes on it. Java deserialization reads the record bytes with `readFully`.
   - Tests: `TestFileGroupReaderIteratorClose` (close and suppression behaviour 
of `closeOnFailure`), `TestFileGroupReaderReleaseOnOpenFailure` (a MOR snapshot 
read that fails to open a log file closes its base file stream), and new cases 
in `TestSerializableIndexRecord` for Kryo and Java serialization, large records 
and updates after serialization.
   
   Existing files touched: `SerializableIndexedRecord.java`, 
`HoodieFileGroupReaderFunction.scala`, `TestSerializableIndexRecord.java`.
   No code was copied from other projects. 3 test files.
   
   ### Impact
   
   No public API change. A failed file group read releases its base file. A 
decoded `SerializableIndexedRecord` is re-encoded each time it is serialized, 
and holds no second copy of its payload.
   
   ### Risk Level
   
   low: the read change only adds cleanup on an error path, and the record 
change keeps the serialized format; each is covered by the tests above.
   
   ### Documentation Update
   
   none
   
   ### Contributor's checklist
   
   - [x] Read through [contributor's 
guide](https://hudi.apache.org/contribute/how-to-contribute)
   - [x] Enough context is provided in the sections above
   - [x] Adequate tests were added if applicable
   


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

Reply via email to