Skip to content

fix(clustering): read spilled log records of a file slice in place instead of copying them to the heap - #20664

Open
nsivabalan wants to merge 1 commit into
apache:branch-0.xfrom
nsivabalan:oss-0x-lazy-file-slice-log-records
Open

nsivabalan wants to merge 1 commit into
apache:branch-0.xfrom
nsivabalan:oss-0x-lazy-file-slice-log-records

Conversation

@nsivabalan

Copy link
Copy Markdown
Contributor

Describe the issue this Pull Request addresses

On branch-0.x, clustering a MERGE_ON_READ file slice on the record (RDD) path, which is used when the row writer is off, fails once the slice's log records spill to disk.

HoodieFileSliceReader (used by MultipleSparkJobExecutionStrategy and JavaExecutionStrategy) extends LogFileIterator. After the base file is merged, LogFileIterator returns the remaining log records through scanner.getRecords().values().iterator(). The scanner's map is an ExternalSpillableMap. Once it has spilled, its values() calls values() on the disk map, and both BitCaskDiskMap and RocksDbDiskMap throw HoodieException: Unsupported Operation Exception there. Even where values() is made to work (HUDI-8860 on master copies the disk map into a list), it copies every record, spilled ones included, into one ArrayList on the heap, so spilling saves no heap.

Not an issue on master (1.x): LogFileIterator and HoodieFileSliceReader no longer exist there. Clustering reads file slices through the file group reader, whose FileGroupRecordBuffer iterates its ExternalSpillableMap in place (records.iterator()). This fix is for branch-0.x only.

Summary and Changelog

The 0.x clustering record path reads the remaining log records of a file slice from the spillable map in place, instead of going through values().

  • LogFileIterator iterates an ExternalSpillableMap with its own iterator(), which walks the in-memory records and then the disk map lazily. Other maps still use values().iterator().
  • The iterator is created only after the base file is drained, so keys removed while merging the base file stay removed with both disk map types (BITCASK snapshots its index when the iterator is created, ROCKS_DB deletes the key).
  • New test TestLogFileIterator: for each disk map type, spills the log records, removes two keys as a base-file merge would, and asserts the exact set of remaining keys and that values() is never called. Without the fix it fails for every disk map type with the Unsupported Operation Exception above.

Impact

Clustering MOR file slices whose log records spill no longer fails on the 0.x record path, and the remaining log records are read without copying them to the heap. No public API or config change.

Risk Level

low. One iteration call changes; the records returned and their removal semantics are the same, as the new test checks for both disk map types.

Documentation Update

none

Contributor's checklist

  • Read through contributor's guide
  • Enough context is provided in the sections above
  • Adequate tests were added if applicable

…stead of copying them to the heap

On the 0.x clustering record path, HoodieFileSliceReader extends LogFileIterator, which returned the log records left after the base-file merge through values() of the scanner's ExternalSpillableMap. Once records spilled, that call fails (the disk maps do not support values()). Iterate the spillable map with its lazy iterator instead.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant